zsh: escape siteFunction names
This commit is contained in:
parent
d29e0ab7c2
commit
19c41a5a6d
2 changed files with 17 additions and 3 deletions
|
|
@ -487,8 +487,13 @@ in
|
|||
home.packages = lib.mapAttrsToList (
|
||||
name: pkgs.writeTextDir "share/zsh/site-functions/${name}"
|
||||
) cfg.siteFunctions;
|
||||
programs.zsh.initContent = concatStringsSep " " (
|
||||
[ "autoload -Uz --" ] ++ lib.attrNames cfg.siteFunctions
|
||||
programs.zsh.initContent = lib.escapeShellArgs (
|
||||
[
|
||||
"autoload"
|
||||
"-Uz"
|
||||
"--"
|
||||
]
|
||||
++ (lib.attrNames cfg.siteFunctions)
|
||||
);
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -5,19 +5,28 @@ let
|
|||
hidden-body = ''
|
||||
echo "doing some hidden magic"
|
||||
'';
|
||||
bad-idea-body = ''
|
||||
echo "zsh can have function names with spaces! you shouldn't use it though..."
|
||||
'';
|
||||
in
|
||||
{
|
||||
programs.zsh = {
|
||||
enable = true;
|
||||
# normal function name
|
||||
siteFunctions.mkcd = mkcd-body;
|
||||
# function name starting with a dash: it should not be treated as an option
|
||||
siteFunctions."-hidden-function" = hidden-body;
|
||||
# function name that contains a space: it should not be word-split (avoid loading 'bad' and 'idea' separately)
|
||||
siteFunctions."bad idea" = bad-idea-body;
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists home-path/share/zsh/site-functions/mkcd
|
||||
assertFileExists home-path/share/zsh/site-functions/-hidden-function
|
||||
assertFileExists "home-path/share/zsh/site-functions/bad idea"
|
||||
assertFileContent home-path/share/zsh/site-functions/mkcd ${builtins.toFile "mkcd" mkcd-body}
|
||||
assertFileContent home-path/share/zsh/site-functions/-hidden-function ${builtins.toFile "-hidden-function" hidden-body}
|
||||
assertFileContains home-files/.zshrc "autoload -Uz -- -hidden-function mkcd"
|
||||
assertFileContent "home-path/share/zsh/site-functions/bad idea" ${builtins.toFile "bad-idea" bad-idea-body}
|
||||
assertFileContains home-files/.zshrc "autoload -Uz -- -hidden-function 'bad idea' mkcd"
|
||||
'';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue