From 8b797c8eea1eba7dfb47f6964103e6e0d134255f Mon Sep 17 00:00:00 2001 From: Stel Abrego Date: Thu, 21 Dec 2023 00:10:04 -0800 Subject: [PATCH] fish: escape abbr expansions once again Commit 8cedd6 `fish: support flexible abbreviations` removed shell escaping for fish shell abbr values. This was a dangerous breaking change offered little value and made writing abbr expansions more difficult. This commit restores automatic shell escaping of fish abbr values. --- modules/programs/fish.nix | 3 ++- tests/modules/programs/fish/abbrs.nix | 26 ++++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/modules/programs/fish.nix b/modules/programs/fish.nix index ac3663ef..7df9704d 100644 --- a/modules/programs/fish.nix +++ b/modules/programs/fish.nix @@ -207,7 +207,8 @@ let modifiers = if isAttrs def then mods else ""; expansion = if isAttrs def then def.expansion else def; in "abbr --add ${modifiers} -- ${name}" - + optionalString (expansion != null) " \"${expansion}\"") cfg.shellAbbrs); + + optionalString (expansion != null) " ${escapeShellArg expansion}") + cfg.shellAbbrs); aliasesStr = concatStringsSep "\n" (mapAttrsToList (k: v: "alias ${k} ${escapeShellArg v}") cfg.shellAliases); diff --git a/tests/modules/programs/fish/abbrs.nix b/tests/modules/programs/fish/abbrs.nix index 681212b8..ce89bcb0 100644 --- a/tests/modules/programs/fish/abbrs.nix +++ b/tests/modules/programs/fish/abbrs.nix @@ -26,8 +26,13 @@ }; "4DIRS" = { setCursor = "!"; - expansion = - "$(string join \\n -- 'for dir in */' 'cd $dir' '!' 'cd ..' 'end')"; + expansion = '' + for dir in */ + cd $dir + ! + cd .. + end + ''; }; dotdot = { regex = "^\\.\\.+$"; @@ -41,19 +46,24 @@ "if fish.shellAbbrs is set, check fish.config contains valid abbreviations"; script = '' assertFileContains home-files/.config/fish/config.fish \ - 'abbr --add -- l less' + "abbr --add -- l less" assertFileContains home-files/.config/fish/config.fish \ - 'abbr --add -- gco "git checkout"' + "abbr --add -- gco 'git checkout'" assertFileContains home-files/.config/fish/config.fish \ - 'abbr --add --position anywhere -- -C --color' + "abbr --add --position anywhere -- -C --color" assertFileContains home-files/.config/fish/config.fish \ - 'abbr --add --position anywhere --set-cursor -- L "% | less"' + "abbr --add --position anywhere --set-cursor -- L '% | less'" assertFileContains home-files/.config/fish/config.fish \ - 'abbr --add --function last_history_item --position anywhere -- !!' + "abbr --add --function last_history_item --position anywhere -- !!" assertFileContains home-files/.config/fish/config.fish \ "abbr --add --function vim_edit --position command --regex '.+\.txt' -- vim_edit_texts" assertFileContains home-files/.config/fish/config.fish \ - 'abbr --add '"'"'--set-cursor=!'"'"' -- 4DIRS "$(string join \n -- '"'"'for dir in */'"'"' '"'"'cd $dir'"'"' '"'"'!'"'"' '"'"'cd ..'"'"' '"'"'end'"'"')' + "abbr --add '--set-cursor=!' -- 4DIRS 'for dir in */ + cd \$dir + ! + cd .. + end + '" assertFileContains home-files/.config/fish/config.fish \ "abbr --add --function multicd --regex '^\.\.+$' -- dotdot" '';