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.
This commit is contained in:
Stel Abrego 2023-12-21 00:10:04 -08:00 committed by Robert Helgesson
parent b897544a79
commit 8b797c8eea
No known key found for this signature in database
GPG Key ID: 36BDAA14C2797E89
2 changed files with 20 additions and 9 deletions

View File

@ -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);

View File

@ -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"
'';