mirror of
https://github.com/nix-community/home-manager.git
synced 2026-06-05 21:02:51 +00:00
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:
@@ -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})
|
||||
''
|
||||
))
|
||||
|
||||
|
||||
@@ -3,6 +3,12 @@
|
||||
programs.zsh = {
|
||||
enable = true;
|
||||
|
||||
cdpath = [
|
||||
"$HOME/projects"
|
||||
"/tmp/with space"
|
||||
"/tmp/with[glob]"
|
||||
];
|
||||
|
||||
initContent = lib.mkMerge [
|
||||
(lib.mkBefore ''
|
||||
# High priority (mkBefore)
|
||||
@@ -34,6 +40,8 @@
|
||||
echo "High priority content"
|
||||
|
||||
typeset -U path cdpath fpath manpath
|
||||
cdpath+=("$HOME/projects" "/tmp/with space" "/tmp/with[glob]")
|
||||
|
||||
for profile in ''${(z)NIX_PROFILES}; do
|
||||
fpath+=($profile/share/zsh/site-functions $profile/share/zsh/$ZSH_VERSION/functions $profile/share/zsh/vendor-completions)
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user