From 7a9389914a347ccfa564d9f5deaa668743392521 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Mon, 24 Mar 2025 16:08:00 -0500 Subject: [PATCH] zsh: fix concatenation of aliases and global aliases Accidentally bump the lines against each other. Adding a newline to move global aliases to another line when you have both. --- modules/programs/zsh.nix | 5 ++- tests/modules/programs/zsh/aliases.nix | 52 ++++++++++++++++++++++++++ tests/modules/programs/zsh/default.nix | 13 ++++--- 3 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 tests/modules/programs/zsh/aliases.nix diff --git a/modules/programs/zsh.nix b/modules/programs/zsh.nix index fe9bffa09..4dffce2b0 100644 --- a/modules/programs/zsh.nix +++ b/modules/programs/zsh.nix @@ -732,10 +732,11 @@ in (lib.mkIf (aliasesStr != "" || cfg.shellGlobalAliases != {}) (mkOrder 1100 ((optionalString (aliasesStr != "") aliasesStr) + - (optionalString (cfg.shellGlobalAliases != {}) + (optionalString (cfg.shellGlobalAliases != {}) + (optionalString (cfg.shellAliases != {}) "\n" + (concatStringsSep "\n" (lib.mapAttrsToList (k: v: "alias -g -- ${lib.escapeShellArg k}=${lib.escapeShellArg v}") - cfg.shellGlobalAliases)))))) + cfg.shellGlobalAliases))))))) (lib.mkIf (dirHashesStr != "") (mkOrder 1150 '' # Named Directory Hashes diff --git a/tests/modules/programs/zsh/aliases.nix b/tests/modules/programs/zsh/aliases.nix new file mode 100644 index 000000000..a3fa2b360 --- /dev/null +++ b/tests/modules/programs/zsh/aliases.nix @@ -0,0 +1,52 @@ +{ config, ... }: + +{ + programs.zsh = { + enable = true; + + shellAliases = { + test1 = "alias"; + test2 = "alias2"; + }; + shellGlobalAliases = { global = "test"; }; + }; + + nmt.script = '' + assertFileExists home-files/.zshrc + + assertFileContent home-files/.zshrc ${ + builtins.toFile "expected-.zshrc" '' + typeset -U path cdpath fpath manpath + 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 + + HELPDIR="@zsh@/share/zsh/$ZSH_VERSION/help" + + autoload -U compinit && compinit + # History options should be set in .zshrc and after oh-my-zsh sourcing. + # See https://github.com/nix-community/home-manager/issues/177. + HISTSIZE="10000" + SAVEHIST="10000" + + HISTFILE="$HOME/.zsh_history" + mkdir -p "$(dirname "$HISTFILE")" + + setopt HIST_FCNTL_LOCK + unsetopt APPEND_HISTORY + setopt HIST_IGNORE_DUPS + unsetopt HIST_IGNORE_ALL_DUPS + unsetopt HIST_SAVE_NO_DUPS + unsetopt HIST_FIND_NO_DUPS + setopt HIST_IGNORE_SPACE + unsetopt HIST_EXPIRE_DUPS_FIRST + setopt SHARE_HISTORY + unsetopt EXTENDED_HISTORY + + + alias -- test1=alias + alias -- test2=alias2 + alias -g -- global=test'' + } + ''; +} diff --git a/tests/modules/programs/zsh/default.nix b/tests/modules/programs/zsh/default.nix index 38e704aac..0e65a4bab 100644 --- a/tests/modules/programs/zsh/default.nix +++ b/tests/modules/programs/zsh/default.nix @@ -1,13 +1,14 @@ { - zsh-session-variables = ./session-variables.nix; - zsh-history-path-new-default = ./history-path-new-default.nix; - zsh-history-path-new-custom = ./history-path-new-custom.nix; - zsh-history-path-old-default = ./history-path-old-default.nix; - zsh-history-path-old-custom = ./history-path-old-custom.nix; + zsh-abbr = ./zsh-abbr.nix; + zsh-aliases = ./aliases.nix; zsh-history-ignore-pattern = ./history-ignore-pattern.nix; + zsh-history-path-new-custom = ./history-path-new-custom.nix; + zsh-history-path-new-default = ./history-path-new-default.nix; + zsh-history-path-old-custom = ./history-path-old-custom.nix; + zsh-history-path-old-default = ./history-path-old-default.nix; zsh-history-substring-search = ./history-substring-search.nix; zsh-prezto = ./prezto.nix; + zsh-session-variables = ./session-variables.nix; zsh-syntax-highlighting = ./syntax-highlighting.nix; - zsh-abbr = ./zsh-abbr.nix; zshrc-contents-priorities = ./zshrc-content-priorities.nix; }