zsh: improve shell{,Global}Aliases

This commit changes the way aliases are rendered, adding the "no more
flags" flag `--`, which means that, for example, the alias `"-" = "cd
-";` will work as expected. (I was getting a syntax error before this
change.)

Additionally, now the alias key is shell escaped, which may help some
edge cases. I'm honestly not sure if this part is necessary since I
assume an alias can't contain spaces anyway, but it definitely
shouldn't break anything.
This commit is contained in:
bri 2024-02-22 11:55:26 -05:00 committed by Robert Helgesson
parent ad9254cd9a
commit cf111d1a84
No known key found for this signature in database
GPG key ID: 96E745BD17AA17ED
2 changed files with 5 additions and 5 deletions

View file

@ -15,7 +15,7 @@ let
localVarsStr = config.lib.zsh.defineAll cfg.localVariables; localVarsStr = config.lib.zsh.defineAll cfg.localVariables;
aliasesStr = concatStringsSep "\n" ( aliasesStr = concatStringsSep "\n" (
mapAttrsToList (k: v: "alias ${k}=${lib.escapeShellArg v}") cfg.shellAliases mapAttrsToList (k: v: "alias -- ${lib.escapeShellArg k}=${lib.escapeShellArg v}") cfg.shellAliases
); );
dirHashesStr = concatStringsSep "\n" ( dirHashesStr = concatStringsSep "\n" (
@ -638,7 +638,7 @@ in
${aliasesStr} ${aliasesStr}
'' ''
] ]
++ (mapAttrsToList (k: v: "alias -g ${k}=${lib.escapeShellArg v}") cfg.shellGlobalAliases) ++ (mapAttrsToList (k: v: "alias -g -- ${lib.escapeShellArg k}=${lib.escapeShellArg v}") cfg.shellGlobalAliases)
++ [ ('' ++ [ (''
# Named Directory Hashes # Named Directory Hashes
${dirHashesStr} ${dirHashesStr}

View file

@ -23,10 +23,10 @@ with lib;
assertFileExists home-files/.zshrc assertFileExists home-files/.zshrc
assertFileContains \ assertFileContains \
home-files/.zshrc \ home-files/.zshrc \
"alias ls='@pls@/bin/pls'" "alias -- 'ls'='@pls@/bin/pls'"
assertFileContains \ assertFileContains \
home-files/.zshrc \ home-files/.zshrc \
"alias ll='@pls@/bin/pls -d perms -d user -d group -d size -d mtime -d git'" "alias -- 'll'='@pls@/bin/pls -d perms -d user -d group -d size -d mtime -d git'"
''; '';
}; };
} }