From 8675edf7d36bfc972f66481a33f4f453d3b2d06e Mon Sep 17 00:00:00 2001 From: Karun Sandhu <129101708+MrSom3body@users.noreply.github.com> Date: Thu, 20 Mar 2025 04:43:42 +0100 Subject: [PATCH] fish: add command option for abbreviations (#6666) The fish shell has added a flag to the abbr command which allows one to expand it only if it is typed after a real command e.g.: git s -> git status s -> s Also see the last example here: https://fishshell.com/docs/current/cmds/abbr.html#examples --- modules/programs/fish.nix | 12 +++++++++++- tests/modules/programs/fish/abbrs.nix | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/programs/fish.nix b/modules/programs/fish.nix index 1fb313a8..73691d5f 100644 --- a/modules/programs/fish.nix +++ b/modules/programs/fish.nix @@ -167,6 +167,16 @@ let ''; }; + command = mkOption { + type = with types; nullOr str; + default = null; + description = '' + Specifies the command(s) for which the abbreviation should expand. If + set, the abbreviation will only expand when used as an argument to + the given command(s). + ''; + }; + setCursor = mkOption { type = with types; (either bool str); default = false; @@ -201,7 +211,7 @@ let (lib.generators.mkValueStringDefault { } v) ]; } { - inherit position regex function; + inherit position regex command function; set-cursor = setCursor; }; modifiers = if isAttrs def then mods else ""; diff --git a/tests/modules/programs/fish/abbrs.nix b/tests/modules/programs/fish/abbrs.nix index ce89bcb0..a46162cc 100644 --- a/tests/modules/programs/fish/abbrs.nix +++ b/tests/modules/programs/fish/abbrs.nix @@ -34,6 +34,10 @@ end ''; }; + co = { + command = "git"; + expansion = "checkout"; + }; dotdot = { regex = "^\\.\\.+$"; function = "multicd"; @@ -64,6 +68,8 @@ cd .. end '" + assertFileContains home-files/.config/fish/config.fish \ + "abbr --add --command git -- co checkout" assertFileContains home-files/.config/fish/config.fish \ "abbr --add --function multicd --regex '^\.\.+$' -- dotdot" '';