zsh: refactor history to use setOptions
This commit is contained in:
parent
2590268ca7
commit
e3dc313032
6 changed files with 56 additions and 123 deletions
|
|
@ -186,6 +186,30 @@ in
|
|||
''
|
||||
];
|
||||
|
||||
programs.zsh.setOptions =
|
||||
let
|
||||
historyOptions = {
|
||||
APPEND_HISTORY = cfg.history.append;
|
||||
HIST_IGNORE_DUPS = cfg.history.ignoreDups;
|
||||
HIST_IGNORE_ALL_DUPS = cfg.history.ignoreAllDups;
|
||||
HIST_SAVE_NO_DUPS = cfg.history.saveNoDups;
|
||||
HIST_FIND_NO_DUPS = cfg.history.findNoDups;
|
||||
HIST_IGNORE_SPACE = cfg.history.ignoreSpace;
|
||||
HIST_EXPIRE_DUPS_FIRST = cfg.history.expireDuplicatesFirst;
|
||||
SHARE_HISTORY = cfg.history.share;
|
||||
EXTENDED_HISTORY = cfg.history.extended;
|
||||
}
|
||||
// lib.optionalAttrs (cfg.autocd != null) {
|
||||
inherit (cfg) autocd;
|
||||
};
|
||||
|
||||
enabledOpts = lib.filterAttrs (_: enabled: enabled) historyOptions;
|
||||
disabledOpts = lib.filterAttrs (_: enabled: !enabled) historyOptions;
|
||||
in
|
||||
[ "HIST_FCNTL_LOCK" ]
|
||||
++ (lib.mapAttrsToList (name: _: name) enabledOpts)
|
||||
++ (lib.mapAttrsToList (name: _: "NO_" + name) disabledOpts);
|
||||
|
||||
programs.zsh.initContent = lib.mkMerge [
|
||||
(lib.mkOrder 910 ''
|
||||
# History options should be set in .zshrc and after oh-my-zsh sourcing.
|
||||
|
|
@ -197,48 +221,6 @@ in
|
|||
) "HISTORY_IGNORE=${lib.escapeShellArg "(${lib.concatStringsSep "|" cfg.history.ignorePatterns})"}"}
|
||||
HISTFILE="${mkShellVarPathStr cfg.history.path}"
|
||||
mkdir -p "$(dirname "$HISTFILE")"
|
||||
|
||||
setopt HIST_FCNTL_LOCK
|
||||
|
||||
${
|
||||
let
|
||||
historyOptions = {
|
||||
APPEND_HISTORY = cfg.history.append;
|
||||
HIST_IGNORE_DUPS = cfg.history.ignoreDups;
|
||||
HIST_IGNORE_ALL_DUPS = cfg.history.ignoreAllDups;
|
||||
HIST_SAVE_NO_DUPS = cfg.history.saveNoDups;
|
||||
HIST_FIND_NO_DUPS = cfg.history.findNoDups;
|
||||
HIST_IGNORE_SPACE = cfg.history.ignoreSpace;
|
||||
HIST_EXPIRE_DUPS_FIRST = cfg.history.expireDuplicatesFirst;
|
||||
SHARE_HISTORY = cfg.history.share;
|
||||
EXTENDED_HISTORY = cfg.history.extended;
|
||||
}
|
||||
// lib.optionalAttrs (cfg.autocd != null) {
|
||||
inherit (cfg) autocd;
|
||||
};
|
||||
|
||||
enabledOpts = lib.filterAttrs (_: enabled: enabled) historyOptions;
|
||||
disabledOpts = lib.filterAttrs (_: enabled: !enabled) historyOptions;
|
||||
in
|
||||
lib.concatStringsSep "\n\n" (
|
||||
lib.filter (s: s != "") [
|
||||
(lib.optionalString (enabledOpts != { }) ''
|
||||
# Enabled history options
|
||||
${lib.hm.zsh.define "enabled_opts" (lib.mapAttrsToList (name: _: name) enabledOpts)}
|
||||
for opt in "''${enabled_opts[@]}"; do
|
||||
setopt "$opt"
|
||||
done
|
||||
unset opt enabled_opts'')
|
||||
(lib.optionalString (disabledOpts != { }) ''
|
||||
# Disabled history options
|
||||
${lib.hm.zsh.define "disabled_opts" (lib.mapAttrsToList (name: _: name) disabledOpts)}
|
||||
for opt in "''${disabled_opts[@]}"; do
|
||||
unsetopt "$opt"
|
||||
done
|
||||
unset opt disabled_opts'')
|
||||
]
|
||||
)
|
||||
}
|
||||
'')
|
||||
|
||||
(lib.mkIf (cfg.historySubstringSearch.enable or false) (
|
||||
|
|
|
|||
|
|
@ -14,26 +14,16 @@ SAVEHIST="10000"
|
|||
HISTFILE="/home/hm-user/.zsh_history"
|
||||
mkdir -p "$(dirname "$HISTFILE")"
|
||||
|
||||
setopt HIST_FCNTL_LOCK
|
||||
|
||||
# Enabled history options
|
||||
enabled_opts=(
|
||||
HIST_IGNORE_DUPS HIST_IGNORE_SPACE SHARE_HISTORY
|
||||
# Set shell options
|
||||
set_opts=(
|
||||
HIST_FCNTL_LOCK HIST_IGNORE_DUPS HIST_IGNORE_SPACE SHARE_HISTORY
|
||||
NO_APPEND_HISTORY NO_EXTENDED_HISTORY NO_HIST_EXPIRE_DUPS_FIRST
|
||||
NO_HIST_FIND_NO_DUPS NO_HIST_IGNORE_ALL_DUPS NO_HIST_SAVE_NO_DUPS
|
||||
)
|
||||
for opt in "${enabled_opts[@]}"; do
|
||||
for opt in "${set_opts[@]}"; do
|
||||
setopt "$opt"
|
||||
done
|
||||
unset opt enabled_opts
|
||||
|
||||
# Disabled history options
|
||||
disabled_opts=(
|
||||
APPEND_HISTORY EXTENDED_HISTORY HIST_EXPIRE_DUPS_FIRST HIST_FIND_NO_DUPS
|
||||
HIST_IGNORE_ALL_DUPS HIST_SAVE_NO_DUPS
|
||||
)
|
||||
for opt in "${disabled_opts[@]}"; do
|
||||
unsetopt "$opt"
|
||||
done
|
||||
unset opt disabled_opts
|
||||
unset opt set_opts
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -31,29 +31,20 @@
|
|||
HISTFILE="/home/hm-user/.zsh_history"
|
||||
mkdir -p "$(dirname "$HISTFILE")"
|
||||
|
||||
setopt HIST_FCNTL_LOCK
|
||||
|
||||
# Enabled history options
|
||||
enabled_opts=(
|
||||
HIST_IGNORE_DUPS HIST_IGNORE_SPACE SHARE_HISTORY
|
||||
# Set shell options
|
||||
set_opts=(
|
||||
HIST_FCNTL_LOCK HIST_IGNORE_DUPS HIST_IGNORE_SPACE SHARE_HISTORY
|
||||
NO_APPEND_HISTORY NO_EXTENDED_HISTORY NO_HIST_EXPIRE_DUPS_FIRST
|
||||
NO_HIST_FIND_NO_DUPS NO_HIST_IGNORE_ALL_DUPS NO_HIST_SAVE_NO_DUPS
|
||||
)
|
||||
for opt in "''${enabled_opts[@]}"; do
|
||||
for opt in "''${set_opts[@]}"; do
|
||||
setopt "$opt"
|
||||
done
|
||||
unset opt enabled_opts
|
||||
|
||||
# Disabled history options
|
||||
disabled_opts=(
|
||||
APPEND_HISTORY EXTENDED_HISTORY HIST_EXPIRE_DUPS_FIRST HIST_FIND_NO_DUPS
|
||||
HIST_IGNORE_ALL_DUPS HIST_SAVE_NO_DUPS
|
||||
)
|
||||
for opt in "''${disabled_opts[@]}"; do
|
||||
unsetopt "$opt"
|
||||
done
|
||||
unset opt disabled_opts
|
||||
unset opt set_opts
|
||||
|
||||
alias -- test1=alias
|
||||
alias -- test2=alias2
|
||||
alias -g -- global=test''}
|
||||
|
||||
'';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,26 +14,16 @@ SAVEHIST="10000"
|
|||
HISTFILE="/home/hm-user/.zsh_history"
|
||||
mkdir -p "$(dirname "$HISTFILE")"
|
||||
|
||||
setopt HIST_FCNTL_LOCK
|
||||
|
||||
# Enabled history options
|
||||
enabled_opts=(
|
||||
HIST_IGNORE_DUPS HIST_IGNORE_SPACE SHARE_HISTORY
|
||||
# Set shell options
|
||||
set_opts=(
|
||||
HIST_FCNTL_LOCK HIST_IGNORE_DUPS HIST_IGNORE_SPACE SHARE_HISTORY
|
||||
NO_APPEND_HISTORY NO_EXTENDED_HISTORY NO_HIST_EXPIRE_DUPS_FIRST
|
||||
NO_HIST_FIND_NO_DUPS NO_HIST_IGNORE_ALL_DUPS NO_HIST_SAVE_NO_DUPS
|
||||
)
|
||||
for opt in "${enabled_opts[@]}"; do
|
||||
for opt in "${set_opts[@]}"; do
|
||||
setopt "$opt"
|
||||
done
|
||||
unset opt enabled_opts
|
||||
|
||||
# Disabled history options
|
||||
disabled_opts=(
|
||||
APPEND_HISTORY EXTENDED_HISTORY HIST_EXPIRE_DUPS_FIRST HIST_FIND_NO_DUPS
|
||||
HIST_IGNORE_ALL_DUPS HIST_SAVE_NO_DUPS
|
||||
)
|
||||
for opt in "${disabled_opts[@]}"; do
|
||||
unsetopt "$opt"
|
||||
done
|
||||
unset opt disabled_opts
|
||||
unset opt set_opts
|
||||
|
||||
source @zsh-history-substring-search@/share/zsh-history-substring-search/zsh-history-substring-search.zsh
|
||||
bindkey "^[[A" history-substring-search-up
|
||||
|
|
|
|||
|
|
@ -14,21 +14,11 @@ SAVEHIST="50000"
|
|||
HISTFILE="/home/hm-user/.zsh_history"
|
||||
mkdir -p "$(dirname "$HISTFILE")"
|
||||
|
||||
setopt HIST_FCNTL_LOCK
|
||||
|
||||
# Disabled history options
|
||||
disabled_opts=(
|
||||
APPEND_HISTORY EXTENDED_HISTORY HIST_EXPIRE_DUPS_FIRST HIST_FIND_NO_DUPS
|
||||
HIST_IGNORE_ALL_DUPS HIST_IGNORE_DUPS HIST_IGNORE_SPACE HIST_SAVE_NO_DUPS
|
||||
SHARE_HISTORY
|
||||
)
|
||||
for opt in "${disabled_opts[@]}"; do
|
||||
unsetopt "$opt"
|
||||
done
|
||||
unset opt disabled_opts
|
||||
|
||||
# Set shell options
|
||||
set_opts=(
|
||||
HIST_FCNTL_LOCK NO_APPEND_HISTORY NO_EXTENDED_HISTORY
|
||||
NO_HIST_EXPIRE_DUPS_FIRST NO_HIST_FIND_NO_DUPS NO_HIST_IGNORE_ALL_DUPS
|
||||
NO_HIST_IGNORE_DUPS NO_HIST_IGNORE_SPACE NO_HIST_SAVE_NO_DUPS NO_SHARE_HISTORY
|
||||
AUTO_LIST AUTO_PARAM_SLASH AUTO_PUSHD ALWAYS_TO_END CORRECT HIST_FCNTL_LOCK
|
||||
HIST_VERIFY INTERACTIVE_COMMENTS MENU_COMPLETE PUSHD_IGNORE_DUPS PUSHD_TO_HOME
|
||||
PUSHD_SILENT NOTIFY PROMPT_SUBST MULTIOS NOFLOWCONTROL NO_CORRECT_ALL
|
||||
|
|
|
|||
|
|
@ -49,26 +49,16 @@
|
|||
HISTFILE="/home/hm-user/.zsh_history"
|
||||
mkdir -p "$(dirname "$HISTFILE")"
|
||||
|
||||
setopt HIST_FCNTL_LOCK
|
||||
|
||||
# Enabled history options
|
||||
enabled_opts=(
|
||||
HIST_IGNORE_DUPS HIST_IGNORE_SPACE SHARE_HISTORY
|
||||
# Set shell options
|
||||
set_opts=(
|
||||
HIST_FCNTL_LOCK HIST_IGNORE_DUPS HIST_IGNORE_SPACE SHARE_HISTORY
|
||||
NO_APPEND_HISTORY NO_EXTENDED_HISTORY NO_HIST_EXPIRE_DUPS_FIRST
|
||||
NO_HIST_FIND_NO_DUPS NO_HIST_IGNORE_ALL_DUPS NO_HIST_SAVE_NO_DUPS
|
||||
)
|
||||
for opt in "''${enabled_opts[@]}"; do
|
||||
for opt in "''${set_opts[@]}"; do
|
||||
setopt "$opt"
|
||||
done
|
||||
unset opt enabled_opts
|
||||
|
||||
# Disabled history options
|
||||
disabled_opts=(
|
||||
APPEND_HISTORY EXTENDED_HISTORY HIST_EXPIRE_DUPS_FIRST HIST_FIND_NO_DUPS
|
||||
HIST_IGNORE_ALL_DUPS HIST_SAVE_NO_DUPS
|
||||
)
|
||||
for opt in "''${disabled_opts[@]}"; do
|
||||
unsetopt "$opt"
|
||||
done
|
||||
unset opt disabled_opts
|
||||
unset opt set_opts
|
||||
|
||||
# Default priority
|
||||
echo "Default priority content"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue