diff --git a/modules/programs/zsh.nix b/modules/programs/zsh.nix index ac42b885e1a7..ac7079297303 100644 --- a/modules/programs/zsh.nix +++ b/modules/programs/zsh.nix @@ -142,6 +142,307 @@ let }; }; + preztoModule = types.submodule { + options = { + enable = mkEnableOption "prezto"; + + caseSensitive = mkOption { + type = types.nullOr types.bool; + default = null; + example = true; + description = "Set case-sensitivity for completion, history lookup, etc."; + }; + + color = mkOption { + type = types.nullOr types.bool; + default = true; + example = false; + description = "Color output (auto set to 'no' on dumb terminals)"; + }; + + pmoduleDirs = mkOption { + type = types.listOf types.path; + default = []; + example = [ "$HOME/.zprezto-contrib" ]; + description = "Add additional directories to load prezto modules from"; + }; + + extraConfig = mkOption { + type = types.lines; + default = ""; + description = '' + Additional configuration to add to .zpreztorc. + ''; + }; + + extraModules = mkOption { + type = types.listOf types.str; + default = []; + example = [ "attr" "stat" ]; + description = "Set the Zsh modules to load (man zshmodules)."; + }; + + extraFunctions = mkOption { + type = types.listOf types.str; + default = []; + example = [ "zargs" "zmv" ]; + description = "Set the Zsh functions to load (man zshcontrib)."; + }; + + pmodules = mkOption { + type = types.listOf types.str; + default = [ "environment" "terminal" "editor" "history" "directory" "spectrum" "utility" "completion" "prompt" ]; + description = "Set the Prezto modules to load (browse modules). The order matters."; + }; + + autosuggestions.color = mkOption { + type = types.nullOr types.str; + default = null; + example = "fg=blue"; + description = "Set the query found color."; + }; + + completions.ignoredHosts = mkOption { + type = types.listOf types.str; + default = []; + example = [ "0.0.0.0" "127.0.0.1" ]; + description = "Set the entries to ignore in static */etc/hosts* for host completion."; + }; + + editor = { + keymap = mkOption { + type = types.nullOr (types.enum ["emacs" "vi"]); + default = "emacs"; + example = "vi"; + description = "Set the key mapping style to 'emacs' or 'vi'."; + }; + + dotExpansion = mkOption { + type = types.nullOr types.bool; + default = null; + example = true; + description = "Auto convert .... to ../.."; + }; + + promptContext = mkOption { + type = types.nullOr types.bool; + default = null; + example = true; + description = "Allow the zsh prompt context to be shown."; + }; + }; + + git.submoduleIgnore = mkOption { + type = types.nullOr (types.enum ["dirty" "untracked" "all" "none"]); + default = null; + example = "all"; + description = "Ignore submodules when they are 'dirty', 'untracked', 'all', or 'none'."; + }; + + gnuUtility.prefix = mkOption { + type = types.nullOr types.str; + default = null; + example = "g"; + description = "Set the command prefix on non-GNU systems."; + }; + + historySubstring = { + foundColor = mkOption { + type = types.nullOr types.str; + default = null; + example = "fg=blue"; + description = "Set the query found color."; + }; + + notFoundColor = mkOption { + type = types.nullOr types.str; + default = null; + example = "fg=red"; + description = "Set the query not found color."; + }; + + globbingFlags = mkOption { + type = types.nullOr types.str; + default = null; + description = "Set the search globbing flags."; + }; + }; + + macOS.dashKeyword = mkOption { + type = types.nullOr types.str; + default = null; + example = "manpages"; + description = "Set the keyword used by `mand` to open man pages in Dash.app"; + }; + + prompt = { + theme = mkOption { + type = types.nullOr types.str; + default = "sorin"; + example = "pure"; + description = "Set the prompt theme to load. Setting it to 'random' + loads a random theme. Auto set to 'off' on dumb terminals."; + }; + + pwdLength = mkOption { + type = types.nullOr (types.enum ["short" "long" "full"]); + default = null; + example = "short"; + description = "Set the working directory prompt display length. By + default, it is set to 'short'. Set it to 'long' (without '~' expansion) for + longer or 'full' (with '~' expansion) for even longer prompt display."; + }; + + showReturnVal = mkOption { + type = types.nullOr types.bool; + default = null; + example = true; + description = "Set the prompt to display the return code along with an + indicator for non-zero return codes. This is not supported by all prompts."; + }; + }; + + python = { + virtualenvAutoSwitch = mkOption { + type = types.nullOr types.bool; + default = null; + example = true; + description = "Auto switch to Python virtualenv on directory change."; + }; + + virtualenvInitialize = mkOption { + type = types.nullOr types.bool; + default = null; + example = true; + description = "Automatically initialize virtualenvwrapper if pre-requisites are met."; + }; + }; + + ruby.chrubyAutoSwitch = mkOption { + type = types.nullOr types.bool; + default = null; + example = true; + description = "Auto switch the Ruby version on directory change."; + }; + + screen = { + autoStartLocal = mkOption { + type = types.nullOr types.bool; + default = null; + example = true; + description = "Auto start a session when Zsh is launched in a local terminal."; + }; + + autoStartRemote = mkOption { + type = types.nullOr types.bool; + default = null; + example = true; + description = "Auto start a session when Zsh is launched in a SSH connection."; + }; + }; + + ssh.identities = mkOption { + type = types.listOf types.str; + default = []; + example = [ "id_rsa" "id_rsa2" "id_github" ]; + description = "Set the SSH identities to load into the agent."; + }; + + syntaxHighlighting = { + highlighters = mkOption { + type = types.listOf types.str; + default = []; + example = [ "main" "brackets" "pattern" "line" "cursor" "root" ]; + description = "Set syntax highlighters. By default, only the main + highlighter is enabled."; + }; + + styles = mkOption { + type = types.attrsOf types.str; + default = {}; + example = { builtin = "bg=blue"; command = "bg=blue"; function = "bg=blue"; }; + description = "Set syntax highlighting styles."; + }; + + pattern = mkOption { + type = types.attrsOf types.str; + default = {}; + example = { "rm*-rf*" = "fg=white,bold,bg=red"; }; + description = "Set syntax pattern styles."; + }; + }; + + terminal = { + autoTitle = mkOption { + type = types.nullOr types.bool; + default = null; + example = true; + description = "Auto set the tab and window titles."; + }; + + windowTitleFormat = mkOption { + type = types.nullOr types.str; + default = null; + example = "%n@%m: %s"; + description = "Set the window title format."; + }; + + tabTitleFormat = mkOption { + type = types.nullOr types.str; + default = null; + example = "%m: %s"; + description = "Set the tab title format."; + }; + + multiplexerTitleFormat = mkOption { + type = types.nullOr types.str; + default = null; + example = "%s"; + description = "Set the multiplexer title format."; + }; + }; + + tmux = { + autoStartLocal = mkOption { + type = types.nullOr types.bool; + default = null; + example = true; + description = "Auto start a session when Zsh is launched in a local terminal."; + }; + + autoStartRemote = mkOption { + type = types.nullOr types.bool; + default = null; + example = true; + description = "Auto start a session when Zsh is launched in a SSH connection."; + }; + + itermIntegration = mkOption { + type = types.nullOr types.bool; + default = null; + example = true; + description = "Integrate with iTerm2."; + }; + + defaultSessionName = mkOption { + type = types.nullOr types.str; + default = null; + example = "YOUR DEFAULT SESSION NAME"; + description = "Set the default session name."; + }; + }; + + utility.safeOps = mkOption { + type = types.nullOr types.bool; + default = null; + example = true; + description = "Enabled safe options. This aliases cp, ln, mv and rm so + that they prompt before deleting or overwriting files. Set to 'no' to disable + this safer behavior."; + }; + }; + }; + in { @@ -275,6 +576,12 @@ in description = "Options to configure oh-my-zsh."; }; + prezto = mkOption { + type = preztoModule; + default = {}; + description = "Options to configure prezto."; + }; + localVariables = mkOption { type = types.attrs; default = {}; @@ -288,15 +595,39 @@ in config = mkIf cfg.enable (mkMerge [ (mkIf (cfg.profileExtra != "") { - home.file."${relToDotDir ".zprofile"}".text = cfg.profileExtra; + home.file."${relToDotDir ".zprofile"}".text = + optionalString cfg.prezto.enable + (builtins.readFile "${pkgs.zsh-prezto}/runcoms/zprofile") + + cfg.profileExtra; + }) + + (mkIf (cfg.prezto.enable && cfg.profileExtra == "") { + home.file."${relToDotDir ".zprofile"}".source = + "${pkgs.zsh-prezto}/runcoms/zprofile"; }) (mkIf (cfg.loginExtra != "") { - home.file."${relToDotDir ".zlogin"}".text = cfg.loginExtra; + home.file."${relToDotDir ".zlogin"}".text = + optionalString cfg.prezto.enable + (builtins.readFile "${pkgs.zsh-prezto}/runcoms/zlogin") + + cfg.loginExtra; + }) + + (mkIf (cfg.prezto.enable && cfg.loginExtra == "") { + home.file."${relToDotDir ".zlogin"}".source = + "${pkgs.zsh-prezto}/runcoms/zlogin"; }) (mkIf (cfg.logoutExtra != "") { - home.file."${relToDotDir ".zlogout"}".text = cfg.logoutExtra; + home.file."${relToDotDir ".zlogout"}".text = + optionalString cfg.prezto.enable + (builtins.readFile "${pkgs.zsh-prezto}/runcoms/zlogout") + + cfg.logoutExtra; + }) + + (mkIf (cfg.prezto.enable && cfg.logoutExtra == "") { + home.file."${relToDotDir ".zlogout"}".source = + "${pkgs.zsh-prezto}/runcoms/zlogout"; }) (mkIf cfg.oh-my-zsh.enable { @@ -306,6 +637,143 @@ in ''; }) + (mkIf cfg.prezto.enable { + home.file."${relToDotDir ".zshenv"}".text = + (builtins.readFile "${pkgs.zsh-prezto}/runcoms/zshenv"); + home.file."${relToDotDir ".zpreztorc"}".text = '' + # Generated by Nix + ${optionalString (cfg.prezto.caseSensitive != null) '' + zstyle ':prezto:*:*' case-sensitive '${if cfg.prezto.caseSensitive then "yes" else "no"}' + ''} + ${optionalString (cfg.prezto.color != null) '' + zstyle ':prezto:*:*' color '${if cfg.prezto.color then "yes" else "no"}' + ''} + ${optionalString (cfg.prezto.pmoduleDirs != []) '' + zstyle ':prezto:load' pmodule-dirs ${builtins.concatStringsSep " " cfg.prezto.pmoduleDirs} + ''} + ${optionalString (cfg.prezto.extraModules != []) '' + zstyle ':prezto:load' zmodule ${strings.concatMapStringsSep " " strings.escapeShellArg cfg.prezto.extraModules} + ''} + ${optionalString (cfg.prezto.extraFunctions != []) '' + zstyle ':prezto:load' zfunction ${strings.concatMapStringsSep " " strings.escapeShellArg cfg.prezto.extraFunctions} + ''} + ${optionalString (cfg.prezto.pmodules != []) '' + zstyle ':prezto:load' pmodule \ + ${strings.concatMapStringsSep " \\\n " strings.escapeShellArg cfg.prezto.pmodules} + ''} + ${optionalString (cfg.prezto.autosuggestions.color != null) '' + zstyle ':prezto:module:autosuggestions:color' found '${cfg.prezto.autosuggestions.color}' + ''} + ${optionalString (cfg.prezto.completions.ignoredHosts != []) '' + zstyle ':prezto:module:completion:*:hosts' etc-host-ignores \ + ${strings.concatMapStringsSep " " strings.escapeShellArg cfg.prezto.completions.ignoredHosts} + ''} + ${optionalString (cfg.prezto.editor.keymap != null) '' + zstyle ':prezto:module:editor' key-bindings '${cfg.prezto.editor.keymap}' + ''} + ${optionalString (cfg.prezto.editor.dotExpansion != null) '' + zstyle ':prezto:module:editor' dot-expansion '${if cfg.prezto.editor.dotExpansion then "yes" else "no"}' + ''} + ${optionalString (cfg.prezto.editor.promptContext != null) '' + zstyle ':prezto:module:editor' ps-context '${if cfg.prezto.editor.promptContext then "yes" else "no"}' + ''} + ${optionalString (cfg.prezto.git.submoduleIgnore != null) '' + zstyle ':prezto:module:git:status:ignore' submodules '${cfg.prezto.git.submoduleIgnore}' + ''} + ${optionalString (cfg.prezto.gnuUtility.prefix != null) '' + zstyle ':prezto:module:gnu-utility' prefix '${cfg.prezto.gnuUtility.prefix}' + ''} + ${optionalString (cfg.prezto.historySubstring.foundColor != null) '' + zstyle ':prezto:module:history-substring-search:color' found '${cfg.prezto.historySubstring.foundColor}' + ''} + ${optionalString (cfg.prezto.historySubstring.notFoundColor != null) '' + zstyle ':prezto:module:history-substring-search:color' not-found '${cfg.prezto.historySubstring.notFoundColor}' + ''} + ${optionalString (cfg.prezto.historySubstring.globbingFlags != null) '' + zstyle ':prezto:module:history-substring-search:color' globbing-flags '${cfg.prezto.historySubstring.globbingFlags}' + ''} + ${optionalString (cfg.prezto.macOS.dashKeyword != null) '' + zstyle ':prezto:module:osx:man' dash-keyword '${cfg.prezto.macOS.dashKeyword}' + ''} + ${optionalString (cfg.prezto.prompt.theme != null) '' + zstyle ':prezto:module:prompt' theme '${cfg.prezto.prompt.theme}' + ''} + ${optionalString (cfg.prezto.prompt.pwdLength != null) '' + zstyle ':prezto:module:prompt' pwd-length '${cfg.prezto.prompt.pwdLength}' + ''} + ${optionalString (cfg.prezto.prompt.showReturnVal != null) '' + zstyle ':prezto:module:prompt' show-return-val '${cfg.prezto.prompt.showReturnVal}' + ''} + ${optionalString (cfg.prezto.python.virtualenvAutoSwitch != null) '' + zstyle ':prezto:module:python:virtualenv' auto-switch '${if cfg.prezto.python.virtualenvAutoSwitch then "yes" else "no"}' + ''} + ${optionalString (cfg.prezto.python.virtualenvInitialize != null) '' + zstyle ':prezto:module:python:virtualenv' initialize '${if cfg.prezto.python.virtualenvInitialize then "yes" else "no"}' + ''} + ${optionalString (cfg.prezto.ruby.chrubyAutoSwitch != null) '' + zstyle ':prezto:module:ruby:chruby' auto-switch '${if cfg.prezto.ruby.chrubyAutoSwitch then "yes" else "no"}' + ''} + ${optionalString (cfg.prezto.screen.autoStartLocal != null) '' + zstyle ':prezto:module:screen:auto-start' local '${if cfg.prezto.screen.autoStartLocal then "yes" else "no"}' + ''} + ${optionalString (cfg.prezto.screen.autoStartRemote != null) '' + zstyle ':prezto:module:screen:auto-start' remote '${if cfg.prezto.screen.autoStartRemote then "yes" else "no"}' + ''} + ${optionalString (cfg.prezto.ssh.identities != []) '' + zstyle ':prezto:module:ssh:load' identities \ + ${strings.concatMapStringsSep " " strings.escapeShellArg cfg.prezto.ssh.identities} + ''} + ${optionalString (cfg.prezto.syntaxHighlighting.highlighters != []) '' + zstyle ':prezto:module:syntax-highlighting' highlighters \ + ${strings.concatMapStringsSep " \\\n " strings.escapeShellArg cfg.prezto.syntaxHighlighting.highlighters} + ''} + ${optionalString (cfg.prezto.syntaxHighlighting.styles != {}) '' + zstyle ':prezto:module:syntax-highlighting' styles \ + ${ builtins.concatStringsSep " \\\n" + (attrsets.mapAttrsToList + (k: v: strings.escapeShellArg k + " " + strings.escapeShellArg v) + cfg.prezto.syntaxHighlighting.styles) + } + ''} + ${optionalString (cfg.prezto.syntaxHighlighting.pattern != {}) '' + zstyle ':prezto:module:syntax-highlighting' pattern \ + ${ builtins.concatStringsSep " \\\n" + (attrsets.mapAttrsToList + (k: v: strings.escapeShellArg k + " " + strings.escapeShellArg v) + cfg.prezto.syntaxHighlighting.pattern) + } + ''} + ${optionalString (cfg.prezto.terminal.autoTitle != null) '' + zstyle ':prezto:module:terminal' auto-title '${if cfg.prezto.terminal.autoTitle then "yes" else "no"}' + ''} + ${optionalString (cfg.prezto.terminal.windowTitleFormat != null) '' + zstyle ':prezto:module:terminal:window-title' format '${cfg.prezto.terminal.windowTitleFormat}' + ''} + ${optionalString (cfg.prezto.terminal.tabTitleFormat != null) '' + zstyle ':prezto:module:terminal:tab-title' format '${cfg.prezto.terminal.tabTitleFormat}' + ''} + ${optionalString (cfg.prezto.terminal.multiplexerTitleFormat != null) '' + zstyle ':prezto:module:terminal:multiplexer-title' format '${cfg.prezto.terminal.multiplexerTitleFormat}' + ''} + ${optionalString (cfg.prezto.tmux.autoStartLocal != null) '' + zstyle ':prezto:module:tmux:auto-start' local '${if cfg.prezto.tmux.autoStartLocal then "yes" else "no"}' + ''} + ${optionalString (cfg.prezto.tmux.autoStartRemote != null) '' + zstyle ':prezto:module:tmux:auto-start' remote '${if cfg.prezto.tmux.autoStartRemote then "yes" else "no"}' + ''} + ${optionalString (cfg.prezto.tmux.itermIntegration != null) '' + zstyle ':prezto:module:tmux:iterm' integrate '${if cfg.prezto.tmux.itermIntegration then "yes" else "no"}' + ''} + ${optionalString (cfg.prezto.tmux.defaultSessionName != null) '' + zstyle ':prezto:module:tmux:session' name '${cfg.prezto.tmux.defaultSessionName}' + ''} + ${optionalString (cfg.prezto.utility.safeOps != null) '' + zstyle ':prezto:module:utility' safe-ops '${if cfg.prezto.utility.safeOps then "yes" else "no"}' + ''} + ${cfg.prezto.extraConfig} + ''; + }) + (mkIf (cfg.dotDir != null) { home.file."${relToDotDir ".zshenv"}".text = '' ZDOTDIR=${zdotdir} @@ -323,7 +791,8 @@ in { home.packages = with pkgs; [ zsh ] ++ optional cfg.enableCompletion nix-zsh-completions - ++ optional cfg.oh-my-zsh.enable oh-my-zsh; + ++ optional cfg.oh-my-zsh.enable oh-my-zsh + ++ optional cfg.prezto.enable zsh-prezto; home.file."${relToDotDir ".zshrc"}".text = '' typeset -U path cdpath fpath manpath @@ -369,6 +838,9 @@ in source $ZSH/oh-my-zsh.sh ''} + ${optionalString cfg.prezto.enable + (builtins.readFile "${pkgs.zsh-prezto}/runcoms/zshrc")} + ${concatStrings (map (plugin: '' if [ -f "$HOME/${pluginsDir}/${plugin.name}/${plugin.file}" ]; then source "$HOME/${pluginsDir}/${plugin.name}/${plugin.file}"