diff --git a/modules/programs/zsh/default.nix b/modules/programs/zsh/default.nix index 34d519946..d6e25b22d 100644 --- a/modules/programs/zsh/default.nix +++ b/modules/programs/zsh/default.nix @@ -395,11 +395,13 @@ in ) cfg.shellAliases ); - dirHashesStr = concatStringsSep "\n" ( - lib.mapAttrsToList (k: v: ''hash -d ${k}="${v}"'') cfg.dirHashes - ); # Keep double quotes so existing configs using shell variables like # $HOME still expand, while escaping chars special inside them. + dirHashesStr = concatStringsSep "\n" ( + lib.mapAttrsToList ( + k: v: ''hash -d ${lib.escapeShellArg k}="${lib.escape [ "\\" "\"" "`" ] v}"'' + ) cfg.dirHashes + ); cdpathStr = concatStringsSep " " (map (v: ''"${lib.escape [ "\\" "\"" "`" ] v}"'') cfg.cdpath); in mkIf cfg.enable ( diff --git a/tests/modules/programs/zsh/zshrc-content-priorities.nix b/tests/modules/programs/zsh/zshrc-content-priorities.nix index 114c7e3f5..6c87e602e 100644 --- a/tests/modules/programs/zsh/zshrc-content-priorities.nix +++ b/tests/modules/programs/zsh/zshrc-content-priorities.nix @@ -8,6 +8,12 @@ "/tmp/with space" "/tmp/with[glob]" ]; + dirHashes = { + docs = "/tmp/with space"; + glob = "/tmp/with[glob]"; + home = "$HOME/Documents"; + quoted = ''/tmp/with "quotes"''; + }; initContent = lib.mkMerge [ (lib.mkBefore '' @@ -71,6 +77,12 @@ # Default priority echo "Default priority content" + # Named Directory Hashes + hash -d docs="/tmp/with space" + hash -d glob="/tmp/with[glob]" + hash -d home="$HOME/Documents" + hash -d quoted="/tmp/with \"quotes\"" + zprof # Low priority (mkAfter) echo "Low priority content"