From bd914d49f1b87fca43ae37ff1beb3ca5e24624b3 Mon Sep 17 00:00:00 2001 From: Nikita Uvarov Date: Wed, 23 Aug 2017 12:51:54 +0200 Subject: [PATCH] zsh: add history submodule --- modules/programs/zsh.nix | 63 ++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/modules/programs/zsh.nix b/modules/programs/zsh.nix index 34c93963c..8526c71dc 100644 --- a/modules/programs/zsh.nix +++ b/modules/programs/zsh.nix @@ -6,6 +6,37 @@ let cfg = config.programs.zsh; + historyModule = types.submodule { + options = { + size = mkOption { + type = types.int; + default = 10000; + description = "Number of history lines to keep."; + }; + + path = mkOption { + type = types.str; + default = "$HOME/.zsh_history"; + description = "History file location"; + }; + + ignoreDups = mkOption { + type = types.bool; + default = true; + description = '' + Do not enter command lines into the history list + if they are duplicates of the previous event. + ''; + }; + + share = mkOption { + type = types.bool; + default = true; + description = "Share command history between zsh sessions."; + }; + }; + }; + in { @@ -13,12 +44,6 @@ in programs.zsh = { enable = mkEnableOption "Z shell (Zsh)"; - historySize = mkOption { - type = types.int; - default = 10000; - description = "Number of history lines to keep."; - }; - shellAliases = mkOption { default = {}; example = { ll = "ls -l"; ".." = "cd .."; }; @@ -31,17 +56,19 @@ in enableCompletion = mkOption { default = true; - description = '' - Enable zsh completion. - ''; + description = "Enable zsh completion."; type = types.bool; }; enableAutosuggestions = mkOption { default = false; - description = '' - Enable zsh autosuggestions - ''; + description = "Enable zsh autosuggestions"; + }; + + history = mkOption { + type = historyModule; + default = {}; + description = "Options related to commands history configuration."; }; initExtra = mkOption { @@ -59,11 +86,6 @@ in ); export = n: v: "export ${n}=\"${toString v}\""; - exportIfNonNull = n: v: optionalString (v != null) (export n v); - exportIfNonEmpty = n: v: optionalString (v != "") (export n v); - - histControlStr = concatStringsSep ":" cfg.historyControl; - histIgnoreStr = concatStringsSep ":" cfg.historyIgnore; envVarsStr = concatStringsSep "\n" ( mapAttrsToList export config.home.sessionVariables @@ -78,7 +100,12 @@ in ''; home.file.".zshrc".text = '' - ${export "HISTSIZE" cfg.historySize} + ${export "HISTSIZE" cfg.history.size} + ${export "HISTFILE" cfg.history.path} + + setopt HIST_FCNTL_LOCK + ${if cfg.history.ignoreDups then "setopt" else "unsetopt"} HIST_IGNORE_DUPS + ${if cfg.history.share then "setopt" else "unsetopt"} SHARE_HISTORY ${if cfg.enableCompletion then "autoload -U compinit && compinit" else ""} ${optionalString (cfg.enableAutosuggestions)