zsh: escape cdpath entries

Zsh cdpath is an array. Rendering entries by joining on spaces breaks paths containing spaces, glob characters, or other shell syntax.

Use the shared shell array formatter so each configured cdpath entry is emitted as a quoted array element.
This commit is contained in:
Austin Horstman
2026-05-18 15:28:15 -05:00
parent 112a3a3783
commit d00b16c511
2 changed files with 12 additions and 1 deletions

View File

@@ -398,6 +398,9 @@ in
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.
cdpathStr = concatStringsSep " " (map (v: ''"${lib.escape [ "\\" "\"" "`" ] v}"'') cfg.cdpath);
in
mkIf cfg.enable (
lib.mkMerge [
@@ -520,7 +523,7 @@ in
(lib.mkIf (cfg.cdpath != [ ]) (
mkOrder 510 ''
cdpath+=(${concatStringsSep " " cfg.cdpath})
cdpath+=(${cdpathStr})
''
))