zsh: refactor history to use setOptions

This commit is contained in:
tarzst 2026-01-25 16:43:52 +05:30 committed by Austin Horstman
parent 2590268ca7
commit e3dc313032
6 changed files with 56 additions and 123 deletions

View file

@ -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

View file

@ -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''}
'';
}

View file

@ -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

View file

@ -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

View file

@ -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"