1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-03-26 01:51:37 +00:00

zsh: cleanup empty / wrong generated lines

We currently just insert a ton of empty lines when not using certain
options. We also incorrectly generate some notes for options not being
used.
This commit is contained in:
Austin Horstman 2025-03-13 11:10:14 -05:00
parent 5d51162862
commit 0e46e84279

View file

@ -627,16 +627,18 @@ in
programs.zsh.initContent = lib.mkMerge [ programs.zsh.initContent = lib.mkMerge [
# zprof must be loaded before everything else, since it # zprof must be loaded before everything else, since it
# benchmarks the shell initialization. # benchmarks the shell initialization.
(mkOrder 400 (optionalString cfg.zprof.enable '' (lib.mkIf cfg.zprof.enable (mkOrder 400 ''
zmodload zsh/zprof zmodload zsh/zprof
'')) ''))
(mkOrder 550 cfg.initExtraFirst) (lib.mkIf (cfg.initExtraFirst != "") (mkOrder 550 cfg.initExtraFirst))
(mkOrder 600 "typeset -U path cdpath fpath manpath") (mkOrder 600 "typeset -U path cdpath fpath manpath")
(mkOrder 650 (optionalString (cfg.cdpath != [ ]) '' (lib.mkIf (cfg.cdpath != [ ]) (mkOrder 650 ''
cdpath+=(${concatStringsSep " " cfg.cdpath}) cdpath+=(${concatStringsSep " " cfg.cdpath})
'')) ''))
(mkOrder 700 '' (mkOrder 700 ''
for profile in ''${(z)NIX_PROFILES}; do for profile in ''${(z)NIX_PROFILES}; do
fpath+=($profile/share/zsh/site-functions $profile/share/zsh/$ZSH_VERSION/functions $profile/share/zsh/vendor-completions) fpath+=($profile/share/zsh/site-functions $profile/share/zsh/$ZSH_VERSION/functions $profile/share/zsh/vendor-completions)
@ -645,41 +647,38 @@ in
HELPDIR="${cfg.package}/share/zsh/$ZSH_VERSION/help" HELPDIR="${cfg.package}/share/zsh/$ZSH_VERSION/help"
'') '')
(mkOrder 750 (optionalString (cfg.defaultKeymap != null) '' (lib.mkIf (cfg.defaultKeymap != null) (mkOrder 750 ''
# Use ${cfg.defaultKeymap} keymap as the default. # Use ${cfg.defaultKeymap} keymap as the default.
${lib.getAttr cfg.defaultKeymap bindkeyCommands} ${lib.getAttr cfg.defaultKeymap bindkeyCommands}
'')) ''))
(mkOrder 800 localVarsStr) (lib.mkIf (localVarsStr != "") (mkOrder 800 localVarsStr))
(mkOrder 850 cfg.initExtraBeforeCompInit)
(mkOrder 900 (lib.concatStrings (map (plugin: '' (lib.mkIf (cfg.initExtraBeforeCompInit != "") (mkOrder 850 cfg.initExtraBeforeCompInit))
(lib.mkIf (cfg.plugins != []) (mkOrder 900 (lib.concatStrings (map (plugin: ''
path+="$HOME/${pluginsDir}/${plugin.name}" path+="$HOME/${pluginsDir}/${plugin.name}"
fpath+="$HOME/${pluginsDir}/${plugin.name}" fpath+="$HOME/${pluginsDir}/${plugin.name}"
'') cfg.plugins))) '') cfg.plugins))))
(mkOrder 950 '' # NOTE: Oh-My-Zsh/Prezto calls compinit during initialization,
# Oh-My-Zsh/Prezto calls compinit during initialization, # calling it twice causes slight start up slowdown
# calling it twice causes slight start up slowdown # as all $fpath entries will be traversed again.
# as all $fpath entries will be traversed again. (lib.mkIf (cfg.enableCompletion && !cfg.oh-my-zsh.enable && !cfg.prezto.enable)
${optionalString (mkOrder 950 cfg.completionInit))
(cfg.enableCompletion && !cfg.oh-my-zsh.enable && !cfg.prezto.enable)
cfg.completionInit}'')
(mkOrder 1000 (optionalString cfg.autosuggestion.enable '' (lib.mkIf cfg.autosuggestion.enable (mkOrder 1000 ''
source ${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh source ${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh
${optionalString (cfg.autosuggestion.strategy != [ ]) '' ${optionalString (cfg.autosuggestion.strategy != [ ]) ''
ZSH_AUTOSUGGEST_STRATEGY=(${ ZSH_AUTOSUGGEST_STRATEGY=(${
concatStringsSep " " cfg.autosuggestion.strategy concatStringsSep " " cfg.autosuggestion.strategy
}) })
''}${optionalString (cfg.autosuggestion.highlight != null) ''
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="${cfg.autosuggestion.highlight}"
''} ''}
'')) ''))
(mkOrder 1050 (optionalString
(cfg.autosuggestion.enable && cfg.autosuggestion.highlight != null) ''
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="${cfg.autosuggestion.highlight}"
''))
(mkOrder 1100 (optionalString cfg.oh-my-zsh.enable '' (lib.mkIf cfg.oh-my-zsh.enable (mkOrder 1100 ''
# oh-my-zsh extra settings for plugins # oh-my-zsh extra settings for plugins
${cfg.oh-my-zsh.extraConfig} ${cfg.oh-my-zsh.extraConfig}
# oh-my-zsh configuration generated by NixOS # oh-my-zsh configuration generated by NixOS
@ -691,16 +690,14 @@ in
''ZSH_THEME="${cfg.oh-my-zsh.theme}"''} ''ZSH_THEME="${cfg.oh-my-zsh.theme}"''}
source $ZSH/oh-my-zsh.sh source $ZSH/oh-my-zsh.sh
'')) ''))
(mkOrder 1150 ''
${optionalString cfg.prezto.enable (builtins.readFile
"${cfg.prezto.package}/share/zsh-prezto/runcoms/zshrc")}
${lib.concatStrings (map (plugin: '' (mkOrder 1150 ((optionalString cfg.prezto.enable (builtins.readFile
"${cfg.prezto.package}/share/zsh-prezto/runcoms/zshrc"))
+ (lib.concatStrings (map (plugin: ''
if [[ -f "$HOME/${pluginsDir}/${plugin.name}/${plugin.file}" ]]; then if [[ -f "$HOME/${pluginsDir}/${plugin.name}/${plugin.file}" ]]; then
source "$HOME/${pluginsDir}/${plugin.name}/${plugin.file}" source "$HOME/${pluginsDir}/${plugin.name}/${plugin.file}"
fi fi
'') cfg.plugins)} '') cfg.plugins)) + ''
# History options should be set in .zshrc and after oh-my-zsh sourcing. # History options should be set in .zshrc and after oh-my-zsh sourcing.
# See https://github.com/nix-community/home-manager/issues/177. # See https://github.com/nix-community/home-manager/issues/177.
HISTSIZE="${toString cfg.history.size}" HISTSIZE="${toString cfg.history.size}"
@ -727,21 +724,23 @@ in
${if cfg.history.share then "setopt" else "unsetopt"} SHARE_HISTORY ${if cfg.history.share then "setopt" else "unsetopt"} SHARE_HISTORY
${if cfg.history.extended then "setopt" else "unsetopt"} EXTENDED_HISTORY ${if cfg.history.extended then "setopt" else "unsetopt"} EXTENDED_HISTORY
${if cfg.autocd != null then "${if cfg.autocd then "setopt" else "unsetopt"} autocd" else ""} ${if cfg.autocd != null then "${if cfg.autocd then "setopt" else "unsetopt"} autocd" else ""}
'') ''))
(mkOrder 1200 cfg.initExtra) (lib.mkIf (cfg.initExtra != "") (mkOrder 1200 cfg.initExtra))
# Aliases (lib.mkIf (aliasesStr != "" || cfg.shellGlobalAliases != {}) (mkOrder 1250
(mkOrder 1250 aliasesStr) ((optionalString (aliasesStr != "") aliasesStr) +
(mkOrder 1250 (concatStringsSep "\n" (lib.mapAttrsToList (optionalString (cfg.shellGlobalAliases != {})
(k: v: "alias -g -- ${lib.escapeShellArg k}=${lib.escapeShellArg v}") (concatStringsSep "\n" (lib.mapAttrsToList
cfg.shellGlobalAliases))) (k: v: "alias -g -- ${lib.escapeShellArg k}=${lib.escapeShellArg v}")
(mkOrder 1300 '' cfg.shellGlobalAliases))))))
(lib.mkIf (dirHashesStr != "") (mkOrder 1300 ''
# Named Directory Hashes # Named Directory Hashes
${dirHashesStr} ${dirHashesStr}
'') ''))
(mkOrder 1350 (optionalString cfg.syntaxHighlighting.enable (lib.mkIf cfg.syntaxHighlighting.enable (mkOrder 1350
# Load zsh-syntax-highlighting after all custom widgets have been created # Load zsh-syntax-highlighting after all custom widgets have been created
# https://github.com/zsh-users/zsh-syntax-highlighting#faq # https://github.com/zsh-users/zsh-syntax-highlighting#faq
'' ''
@ -759,8 +758,7 @@ in
)} )}
'')) ''))
(mkOrder 1400 (optionalString (lib.mkIf (cfg.historySubstringSearch.enable or false) (mkOrder 1400
(cfg.historySubstringSearch.enable or false)
# Load zsh-history-substring-search after zsh-syntax-highlighting # Load zsh-history-substring-search after zsh-syntax-highlighting
# https://github.com/zsh-users/zsh-history-substring-search#usage # https://github.com/zsh-users/zsh-history-substring-search#usage
'' ''
@ -773,9 +771,7 @@ in
(lib.toList cfg.historySubstringSearch.searchDownKey)} (lib.toList cfg.historySubstringSearch.searchDownKey)}
'')) ''))
(mkOrder 1450 (optionalString cfg.zprof.enable '' (lib.mkIf cfg.zprof.enable (mkOrder 1450 "zprof"))
zprof
''))
]; ];
home.file."${relToDotDir ".zshrc"}".text = cfg.initContent; home.file."${relToDotDir ".zshrc"}".text = cfg.initContent;