1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-03 07:31:03 +01:00
home-manager/tests/modules/programs/zsh/zshrc-content-priorities.nix
Austin Horstman 04f672b5db zsh/history: optimize history options with array-based loops
Replace individual setopt/unsetopt statements for history options with efficient
array-based loops. Also optimize history substring search key bindings using
the same pattern. Use lib.hm.zsh.define for consistent array formatting and
add unset statements to clean up temporary variables.

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
2025-09-27 13:18:01 -05:00

86 lines
2.2 KiB
Nix

{ lib, pkgs, ... }:
{
programs.zsh = {
enable = true;
initContent = lib.mkMerge [
(lib.mkBefore ''
# High priority (mkBefore)
echo "High priority content"
'')
(lib.mkAfter ''
# Low priority (mkAfter)
echo "Low priority content"
'')
''
# Default priority
echo "Default priority content"
''
];
zprof.enable = true;
};
nmt.script =
let
expectedFile = pkgs.writeTextFile {
name = ".zshrc";
text = ''
zmodload zsh/zprof
# High priority (mkBefore)
echo "High priority content"
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/hm-user/.zsh_history"
mkdir -p "$(dirname "$HISTFILE")"
setopt HIST_FCNTL_LOCK
# Enabled history options
enabled_opts=(
HIST_IGNORE_DUPS HIST_IGNORE_SPACE SHARE_HISTORY
)
for opt in "''${enabled_opts[@]}"; do
setopt "$opt"
done
unset opt enabled_opts
# Disabled history options
disabled_opts=(
APPEND_HISTORY EXTENDED_HISTORY HIST_EXPIRE_DUPS_FIRST HIST_FIND_NO_DUPS
HIST_IGNORE_ALL_DUPS HIST_SAVE_NO_DUPS
)
for opt in "''${disabled_opts[@]}"; do
unsetopt "$opt"
done
unset opt disabled_opts
# Default priority
echo "Default priority content"
zprof
# Low priority (mkAfter)
echo "Low priority content"
'';
};
in
''
assertFileExists home-files/.zshrc
assertFileContent home-files/.zshrc ${expectedFile}
'';
}