feat(fish): add shell shortcut registry #62

Merged
alexion merged 1 commits from impl/shell-shortcut-registry into main 2026-08-24 23:55:24 -04:00
8 changed files with 136 additions and 35 deletions

View File

@@ -305,6 +305,54 @@
touch $out touch $out
''; '';
shell-shortcut-registry-fish-abbreviations =
let
testConfig = self.nixosConfigurations.neogaia.config;
user = testConfig.user.name;
shortcuts = testConfig.registry.shell-shortcut.${testConfig.networking.hostName};
fishConfig = testConfig.home-manager.users.${user}.programs.fish;
abbrs = fishConfig.shellAbbrs;
aliases = fishConfig.shellAliases;
expectedAliases = {
ls = "eza -alg --color=always --group-directories-first --icons=always";
la = "eza -a --color=always --group-directories-first --icons=always";
ll = "eza -lg --color=always --group-directories-first --icons=always";
lt = "eza -aT -I '.git' --color=always --group-directories-first --icons=always";
"l." = "eza -a | grep -e '^\\.'";
};
expectedAbbrs = {
".." = "cd ..";
"..." = "cd ../..";
"...." = "cd ../../..";
vi = "nvim";
vim = "nvim";
cp = "cp -v";
tmx = "tmux new-session -A -s";
hs = "herdr --session";
tarnow = "tar -acf ";
untar = "tar -zxvf ";
wget = "wget -c ";
grep = "grep --color=auto";
fgrep = "fgrep --color=auto";
egrep = "egrep --color=auto";
jctl = "journalctl -p 3 -xb";
update = "sudo nixos-rebuild switch --flake .#${testConfig.networking.hostName}";
cleanup = "sudo nix-collect-garbage -d";
};
in
pkgs.runCommand "shell-shortcut-registry-fish-abbreviations-check" { } ''
${
lib.optionalString (
!(
lib.mapAttrs (_name: shortcut: shortcut.command) shortcuts == (expectedAliases // expectedAbbrs)
&& lib.filterAttrs (name: _value: builtins.hasAttr name expectedAliases) aliases == expectedAliases
&& lib.filterAttrs (name: _value: builtins.hasAttr name expectedAbbrs) abbrs == expectedAbbrs
)
) "exit 1"
}
touch $out
'';
address-registry = address-registry =
let let
hostAddressConfig = hostAddressConfig =

View File

@@ -13,6 +13,7 @@
# The modules tree reaches for these option namespaces, so they must be # The modules tree reaches for these option namespaces, so they must be
# declared for the tree to evaluate even where a guest leaves them off. # declared for the tree to evaluate even where a guest leaves them off.
my.registry.module
inputs.sops-nix.nixosModules.sops inputs.sops-nix.nixosModules.sops
inputs.stylix.nixosModules.stylix inputs.stylix.nixosModules.stylix
]; ];

View File

@@ -13,6 +13,8 @@ in
options.modules.agents.herdr.enable = lib.mkEnableOption "Herdr, a terminal multiplexer for coding agents"; options.modules.agents.herdr.enable = lib.mkEnableOption "Herdr, a terminal multiplexer for coding agents";
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
registry.shell-shortcut.${config.networking.hostName}.hs = "herdr --session";
home-manager.users.${user} = { home-manager.users.${user} = {
home.packages = [ pkgs.herdr ]; home.packages = [ pkgs.herdr ];

View File

@@ -8,6 +8,8 @@
let let
cfg = config.modules.fish; cfg = config.modules.fish;
user = config.user.name; user = config.user.name;
shortcuts = config.registry.shell-shortcut.${config.networking.hostName};
commandsOf = shortcuts: lib.mapAttrs (_name: shortcut: shortcut.command) shortcuts;
in in
{ {
options.modules.fish = { options.modules.fish = {
@@ -27,10 +29,8 @@ in
home-manager.users.${user} = { home-manager.users.${user} = {
home.packages = with pkgs; [ home.packages = with pkgs; [
eza # backs the ls/la/ll aliases
bat # backs the manpager bat # backs the manpager
fastfetch # the shell greeting fastfetch # the shell greeting
wget # backs the wget abbreviation
]; ];
programs.fish = { programs.fish = {
@@ -51,38 +51,8 @@ in
} }
]; ];
shellAliases = { shellAliases = commandsOf (lib.filterAttrs (_name: shortcut: !shortcut.abbreviation) shortcuts);
ls = "eza -alg --color=always --group-directories-first --icons=always"; shellAbbrs = commandsOf (lib.filterAttrs (_name: shortcut: shortcut.abbreviation) shortcuts);
la = "eza -a --color=always --group-directories-first --icons=always";
ll = "eza -lg --color=always --group-directories-first --icons=always";
lt = "eza -aT -I '.git' --color=always --group-directories-first --icons=always";
"l." = "eza -a | grep -e '^\\.'";
};
shellAbbrs = {
# Walk up the tree.
".." = "cd ..";
"..." = "cd ../..";
"...." = "cd ../../..";
vi = "nvim";
vim = "nvim";
cp = "cp -v";
tmx = "tmux new-session -A -s";
hs = "herdr --session";
tarnow = "tar -acf ";
untar = "tar -zxvf ";
wget = "wget -c ";
grep = "grep --color=auto";
fgrep = "fgrep --color=auto";
egrep = "egrep --color=auto";
jctl = "journalctl -p 3 -xb";
# Rebuild the system, and reclaim disk from old generations.
update = "sudo nixos-rebuild switch --flake .#${config.networking.hostName}";
cleanup = "sudo nix-collect-garbage -d";
};
functions = { functions = {
# Pick the logo that fits the terminal so the greeting never wraps. # Pick the logo that fits the terminal so the greeting never wraps.

View File

@@ -14,6 +14,11 @@ in
options.modules.nvim.enable = lib.mkEnableOption "Neovim, configured declaratively via nixvim"; options.modules.nvim.enable = lib.mkEnableOption "Neovim, configured declaratively via nixvim";
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
registry.shell-shortcut.${config.networking.hostName} = {
vi = "nvim";
vim = "nvim";
};
home-manager.sharedModules = [ inputs.nixvim.homeModules.nixvim ]; home-manager.sharedModules = [ inputs.nixvim.homeModules.nixvim ];
home-manager.users.${user} = hm: { home-manager.users.${user} = hm: {

View File

@@ -13,6 +13,8 @@ in
options.modules.tmux.enable = lib.mkEnableOption "tmux, configured via home-manager"; options.modules.tmux.enable = lib.mkEnableOption "tmux, configured via home-manager";
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
registry.shell-shortcut.${config.networking.hostName}.tmx = "tmux new-session -A -s";
home-manager.users.${user}.programs.tmux = { home-manager.users.${user}.programs.tmux = {
enable = true; enable = true;

View File

@@ -1,7 +1,13 @@
{ config, lib, ... }: {
config,
lib,
pkgs,
...
}:
# The baseline interactive toolset as one deliberate bundle. # The baseline interactive toolset as one deliberate bundle.
let let
cfg = config.modules.toolkit; cfg = config.modules.toolkit;
user = config.user.name;
in in
{ {
options.modules.toolkit.enable = options.modules.toolkit.enable =
@@ -9,6 +15,52 @@ in
# Each piece is turned on at default priority, so a host can still override any one of them. # Each piece is turned on at default priority, so a host can still override any one of them.
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
home-manager.users.${user}.home.packages = with pkgs; [
eza
wget
];
registry.shell-shortcut.${config.networking.hostName} = {
ls = {
command = "eza -alg --color=always --group-directories-first --icons=always";
abbreviation = false;
};
la = {
command = "eza -a --color=always --group-directories-first --icons=always";
abbreviation = false;
};
ll = {
command = "eza -lg --color=always --group-directories-first --icons=always";
abbreviation = false;
};
lt = {
command = "eza -aT -I '.git' --color=always --group-directories-first --icons=always";
abbreviation = false;
};
"l." = {
command = "eza -a | grep -e '^\\.'";
abbreviation = false;
};
# Walk up the tree.
".." = "cd ..";
"..." = "cd ../..";
"...." = "cd ../../..";
cp = "cp -v";
tarnow = "tar -acf ";
untar = "tar -zxvf ";
wget = "wget -c ";
grep = "grep --color=auto";
fgrep = "fgrep --color=auto";
egrep = "egrep --color=auto";
jctl = "journalctl -p 3 -xb";
# Rebuild the system, and reclaim disk from old generations.
update = "sudo nixos-rebuild switch --flake .#${config.networking.hostName}";
cleanup = "sudo nix-collect-garbage -d";
};
modules.fish.enable = lib.mkDefault true; modules.fish.enable = lib.mkDefault true;
# fish is also the login shell, so the bundled environment is what a shell drops into. # fish is also the login shell, so the bundled environment is what a shell drops into.
modules.fish.defaultShell = lib.mkDefault true; modules.fish.defaultShell = lib.mkDefault true;

View File

@@ -0,0 +1,21 @@
{ lib }:
let
entryType = lib.types.submodule {
options = {
command = lib.mkOption {
type = lib.types.str;
example = "nvim";
description = "Command expanded by this shell shortcut.";
};
abbreviation = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether fish realizes this shell shortcut as an abbreviation instead of an alias.";
};
};
};
in
{
type = lib.types.coercedTo lib.types.str (command: { inherit command; }) entryType;
}