From cb59b187031bc99d2038b09e127fbbc415ec31d9 Mon Sep 17 00:00:00 2001 From: alexion Date: Mon, 24 Aug 2026 22:45:44 -0400 Subject: [PATCH] feat(fish): add shell shortcut registry --- flake.nix | 48 +++++++++++++++++++++++++++++++++ guest.nix | 1 + modules/agents/herdr.nix | 2 ++ modules/fish/fish.nix | 38 +++----------------------- modules/nvim/nvim.nix | 5 ++++ modules/tmux/tmux.nix | 2 ++ modules/toolkit.nix | 54 ++++++++++++++++++++++++++++++++++++- registry/shell-shortcut.nix | 21 +++++++++++++++ 8 files changed, 136 insertions(+), 35 deletions(-) create mode 100644 registry/shell-shortcut.nix diff --git a/flake.nix b/flake.nix index 7df05a1..acac491 100644 --- a/flake.nix +++ b/flake.nix @@ -305,6 +305,54 @@ 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 = let hostAddressConfig = diff --git a/guest.nix b/guest.nix index aedba9b..556a835 100644 --- a/guest.nix +++ b/guest.nix @@ -13,6 +13,7 @@ # 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. + my.registry.module inputs.sops-nix.nixosModules.sops inputs.stylix.nixosModules.stylix ]; diff --git a/modules/agents/herdr.nix b/modules/agents/herdr.nix index 12e25df..6669b26 100644 --- a/modules/agents/herdr.nix +++ b/modules/agents/herdr.nix @@ -13,6 +13,8 @@ in options.modules.agents.herdr.enable = lib.mkEnableOption "Herdr, a terminal multiplexer for coding agents"; config = lib.mkIf cfg.enable { + registry.shell-shortcut.${config.networking.hostName}.hs = "herdr --session"; + home-manager.users.${user} = { home.packages = [ pkgs.herdr ]; diff --git a/modules/fish/fish.nix b/modules/fish/fish.nix index da9acb4..67fbcd8 100644 --- a/modules/fish/fish.nix +++ b/modules/fish/fish.nix @@ -8,6 +8,8 @@ let cfg = config.modules.fish; user = config.user.name; + shortcuts = config.registry.shell-shortcut.${config.networking.hostName}; + commandsOf = shortcuts: lib.mapAttrs (_name: shortcut: shortcut.command) shortcuts; in { options.modules.fish = { @@ -27,10 +29,8 @@ in home-manager.users.${user} = { home.packages = with pkgs; [ - eza # backs the ls/la/ll aliases bat # backs the manpager fastfetch # the shell greeting - wget # backs the wget abbreviation ]; programs.fish = { @@ -51,38 +51,8 @@ in } ]; - shellAliases = { - 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 '^\\.'"; - }; - - 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"; - }; + shellAliases = commandsOf (lib.filterAttrs (_name: shortcut: !shortcut.abbreviation) shortcuts); + shellAbbrs = commandsOf (lib.filterAttrs (_name: shortcut: shortcut.abbreviation) shortcuts); functions = { # Pick the logo that fits the terminal so the greeting never wraps. diff --git a/modules/nvim/nvim.nix b/modules/nvim/nvim.nix index 3272356..e96e3f5 100644 --- a/modules/nvim/nvim.nix +++ b/modules/nvim/nvim.nix @@ -14,6 +14,11 @@ in options.modules.nvim.enable = lib.mkEnableOption "Neovim, configured declaratively via nixvim"; config = lib.mkIf cfg.enable { + registry.shell-shortcut.${config.networking.hostName} = { + vi = "nvim"; + vim = "nvim"; + }; + home-manager.sharedModules = [ inputs.nixvim.homeModules.nixvim ]; home-manager.users.${user} = hm: { diff --git a/modules/tmux/tmux.nix b/modules/tmux/tmux.nix index c049ac1..925fca8 100644 --- a/modules/tmux/tmux.nix +++ b/modules/tmux/tmux.nix @@ -13,6 +13,8 @@ in options.modules.tmux.enable = lib.mkEnableOption "tmux, configured via home-manager"; config = lib.mkIf cfg.enable { + registry.shell-shortcut.${config.networking.hostName}.tmx = "tmux new-session -A -s"; + home-manager.users.${user}.programs.tmux = { enable = true; diff --git a/modules/toolkit.nix b/modules/toolkit.nix index 63a831e..564d765 100644 --- a/modules/toolkit.nix +++ b/modules/toolkit.nix @@ -1,7 +1,13 @@ -{ config, lib, ... }: +{ + config, + lib, + pkgs, + ... +}: # The baseline interactive toolset as one deliberate bundle. let cfg = config.modules.toolkit; + user = config.user.name; in { 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. 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; # fish is also the login shell, so the bundled environment is what a shell drops into. modules.fish.defaultShell = lib.mkDefault true; diff --git a/registry/shell-shortcut.nix b/registry/shell-shortcut.nix new file mode 100644 index 0000000..704e15c --- /dev/null +++ b/registry/shell-shortcut.nix @@ -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; +} -- 2.47.3