fix zsh history

This commit is contained in:
thek4n 2026-03-12 18:48:19 +03:00
parent 61e71e1771
commit 91adc03b90
2 changed files with 23 additions and 15 deletions

View File

@ -11,6 +11,8 @@ setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a dupl
setopt HIST_IGNORE_SPACE # Don't record an entry starting with a space.
setopt HIST_FIND_NO_DUPS # Do not display a line previously found.
setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file.
setopt HIST_REDUCE_BLANKS # Убирать лишние пробелы из командных строк, добавляемых в историю.
setopt HIST_NO_STORE # Не хранить записи о командах history.
export HISTSIZE=100000
@ -29,4 +31,4 @@ zshaddhistory() {
## should use EXTENDED_GLOB syntax
setopt extendedglob
[[ ${1::-1} != ${~HISTORY_IGNORE} ]]
}
}

View File

@ -89,22 +89,28 @@ zle -N cddotdot
bindkey "^O" cddotdot
bindkey -M vicmd "^O" cddotdot
fzfhistory() {
local cmd
cmd=$(fc -l 1 | \
sed 's/^[ ]*[0-9]*[ ]*//' | \
fzf \
--ignore-case \
--scheme=history \
--no-multi \
--tac \
--tiebreak=begin,index \
--height="$((${LINES}/4))" \
--query="${BUFFER}" \
--preview="echo {} | sed 's/\\\n/\\n/g' | highlight -O ansi -S zsh" \
--preview-window=wrap:30%:50% | sed 's/\\n/\n/g')
cmd=$(fc -il 1 | \
awk '{
original = $0;
clean = $0;
sub(/^[ ]*[0-9]+[ ]+[0-9]{4}-[0-9]{2}-[0-9]{2}[ ]+[0-9]{2}:[0-9]{2}[ ]*/, "", clean);
print clean "\t" original
}' | \
fzf \
--ignore-case \
--scheme=history \
--no-multi \
--tac \
--tiebreak=begin,index \
--height="$((${LINES}/4))" \
--query="${BUFFER}" \
--delimiter=$'\t' \
--with-nth=1 \
--preview="echo {2} | sed 's/\\\n/\\n/g' | highlight -O ansi -S zsh" \
--preview-window=wrap:30%:50% | \
cut -f1 | sed 's/\\n/\n/g')
if [[ -n "${cmd}" ]]; then
BUFFER="${cmd}"