From cf111d1a849ddfc38e9155be029519b0e2329615 Mon Sep 17 00:00:00 2001 From: bri <284789+b-@users.noreply.github.com> Date: Thu, 22 Feb 2024 11:55:26 -0500 Subject: [PATCH] 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. --- modules/programs/zsh.nix | 6 +++--- tests/modules/programs/pls/zsh.nix | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/programs/zsh.nix b/modules/programs/zsh.nix index 392d2632..dcff129d 100644 --- a/modules/programs/zsh.nix +++ b/modules/programs/zsh.nix @@ -15,7 +15,7 @@ let localVarsStr = config.lib.zsh.defineAll cfg.localVariables; 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" ( @@ -637,8 +637,8 @@ in # Aliases ${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 ${dirHashesStr} diff --git a/tests/modules/programs/pls/zsh.nix b/tests/modules/programs/pls/zsh.nix index f3bcbf2a..3a27c4d3 100644 --- a/tests/modules/programs/pls/zsh.nix +++ b/tests/modules/programs/pls/zsh.nix @@ -23,10 +23,10 @@ with lib; assertFileExists home-files/.zshrc assertFileContains \ home-files/.zshrc \ - "alias ls='@pls@/bin/pls'" + "alias -- 'ls'='@pls@/bin/pls'" assertFileContains \ 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'" ''; }; }