mirror of
https://github.com/nix-community/home-manager
synced 2024-11-27 05:29:46 +01:00
zsh: add history submodule
This commit is contained in:
parent
fed112e497
commit
bd914d49f1
1 changed files with 45 additions and 18 deletions
|
@ -6,6 +6,37 @@ let
|
||||||
|
|
||||||
cfg = config.programs.zsh;
|
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
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -13,12 +44,6 @@ in
|
||||||
programs.zsh = {
|
programs.zsh = {
|
||||||
enable = mkEnableOption "Z shell (Zsh)";
|
enable = mkEnableOption "Z shell (Zsh)";
|
||||||
|
|
||||||
historySize = mkOption {
|
|
||||||
type = types.int;
|
|
||||||
default = 10000;
|
|
||||||
description = "Number of history lines to keep.";
|
|
||||||
};
|
|
||||||
|
|
||||||
shellAliases = mkOption {
|
shellAliases = mkOption {
|
||||||
default = {};
|
default = {};
|
||||||
example = { ll = "ls -l"; ".." = "cd .."; };
|
example = { ll = "ls -l"; ".." = "cd .."; };
|
||||||
|
@ -31,17 +56,19 @@ in
|
||||||
|
|
||||||
enableCompletion = mkOption {
|
enableCompletion = mkOption {
|
||||||
default = true;
|
default = true;
|
||||||
description = ''
|
description = "Enable zsh completion.";
|
||||||
Enable zsh completion.
|
|
||||||
'';
|
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
};
|
};
|
||||||
|
|
||||||
enableAutosuggestions = mkOption {
|
enableAutosuggestions = mkOption {
|
||||||
default = false;
|
default = false;
|
||||||
description = ''
|
description = "Enable zsh autosuggestions";
|
||||||
Enable zsh autosuggestions
|
};
|
||||||
'';
|
|
||||||
|
history = mkOption {
|
||||||
|
type = historyModule;
|
||||||
|
default = {};
|
||||||
|
description = "Options related to commands history configuration.";
|
||||||
};
|
};
|
||||||
|
|
||||||
initExtra = mkOption {
|
initExtra = mkOption {
|
||||||
|
@ -59,11 +86,6 @@ in
|
||||||
);
|
);
|
||||||
|
|
||||||
export = n: v: "export ${n}=\"${toString v}\"";
|
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" (
|
envVarsStr = concatStringsSep "\n" (
|
||||||
mapAttrsToList export config.home.sessionVariables
|
mapAttrsToList export config.home.sessionVariables
|
||||||
|
@ -78,7 +100,12 @@ in
|
||||||
'';
|
'';
|
||||||
|
|
||||||
home.file.".zshrc".text = ''
|
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 ""}
|
${if cfg.enableCompletion then "autoload -U compinit && compinit" else ""}
|
||||||
${optionalString (cfg.enableAutosuggestions)
|
${optionalString (cfg.enableAutosuggestions)
|
||||||
|
|
Loading…
Reference in a new issue