1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-22 17:59:48 +01:00

programs.zsh: generate a more compact config (#3170)

This commit is contained in:
Matthieu Coudron 2022-11-18 17:27:43 +01:00 committed by GitHub
parent 5589b28e66
commit 948d1f8a5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,10 +18,6 @@ let
mapAttrsToList (k: v: "alias ${k}=${lib.escapeShellArg v}") cfg.shellAliases mapAttrsToList (k: v: "alias ${k}=${lib.escapeShellArg v}") cfg.shellAliases
); );
globalAliasesStr = concatStringsSep "\n" (
mapAttrsToList (k: v: "alias -g ${k}=${lib.escapeShellArg v}") cfg.shellGlobalAliases
);
dirHashesStr = concatStringsSep "\n" ( dirHashesStr = concatStringsSep "\n" (
mapAttrsToList (k: v: ''hash -d ${k}="${v}"'') cfg.dirHashes mapAttrsToList (k: v: ''hash -d ${k}="${v}"'') cfg.dirHashes
); );
@ -488,35 +484,36 @@ in
++ optional cfg.enableCompletion nix-zsh-completions ++ optional cfg.enableCompletion nix-zsh-completions
++ optional cfg.oh-my-zsh.enable oh-my-zsh; ++ optional cfg.oh-my-zsh.enable oh-my-zsh;
home.file."${relToDotDir ".zshrc"}".text = '' home.file."${relToDotDir ".zshrc"}".text = concatStringsSep "\n" ([
${cfg.initExtraFirst} cfg.initExtraFirst
"typeset -U path cdpath fpath manpath"
typeset -U path cdpath fpath manpath (optionalString (cfg.cdpath != []) ''
${optionalString (cfg.cdpath != []) ''
cdpath+=(${concatStringsSep " " cfg.cdpath}) cdpath+=(${concatStringsSep " " cfg.cdpath})
''} '')
''
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)
done done
HELPDIR="${pkgs.zsh}/share/zsh/$ZSH_VERSION/help" HELPDIR="${pkgs.zsh}/share/zsh/$ZSH_VERSION/help"
''
${optionalString (cfg.defaultKeymap != null) '' (optionalString (cfg.defaultKeymap != null) ''
# Use ${cfg.defaultKeymap} keymap as the default. # Use ${cfg.defaultKeymap} keymap as the default.
${getAttr cfg.defaultKeymap bindkeyCommands} ${getAttr cfg.defaultKeymap bindkeyCommands}
''} '')
localVarsStr
${localVarsStr} cfg.initExtraBeforeCompInit
${cfg.initExtraBeforeCompInit} (concatStrings (map (plugin: ''
${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))
''
# 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.
@ -575,27 +572,29 @@ in
# Aliases # Aliases
${aliasesStr} ${aliasesStr}
''
# Global Aliases ]
${globalAliasesStr} ++ (mapAttrsToList (k: v: "alias -g ${k}=${lib.escapeShellArg v}") cfg.shellGlobalAliases)
++ [ (''
# Named Directory Hashes # Named Directory Hashes
${dirHashesStr} ${dirHashesStr}
'')
${optionalString cfg.enableSyntaxHighlighting (optionalString cfg.enableSyntaxHighlighting
# 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
"source ${pkgs.zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" "source ${pkgs.zsh-syntax-highlighting}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
} )
${optionalString (cfg.historySubstringSearch.enable or false)
(optionalString (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
'' ''
source ${pkgs.zsh-history-substring-search}/share/zsh-history-substring-search/zsh-history-substring-search.zsh source ${pkgs.zsh-history-substring-search}/share/zsh-history-substring-search/zsh-history-substring-search.zsh
bindkey '${cfg.historySubstringSearch.searchUpKey}' history-substring-search-up bindkey '${cfg.historySubstringSearch.searchUpKey}' history-substring-search-up
bindkey '${cfg.historySubstringSearch.searchDownKey}' history-substring-search-down bindkey '${cfg.historySubstringSearch.searchDownKey}' history-substring-search-down
''} '')
''; ]);
} }
(mkIf cfg.oh-my-zsh.enable { (mkIf cfg.oh-my-zsh.enable {