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_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_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_SAVE_NO_DUPS # Don't write duplicate entries in the history file.
setopt HIST_REDUCE_BLANKS # Убирать лишние пробелы из командных строк, добавляемых в историю.
setopt HIST_NO_STORE # Не хранить записи о командах history.
export HISTSIZE=100000 export HISTSIZE=100000

View File

@ -89,12 +89,15 @@ zle -N cddotdot
bindkey "^O" cddotdot bindkey "^O" cddotdot
bindkey -M vicmd "^O" cddotdot bindkey -M vicmd "^O" cddotdot
fzfhistory() { fzfhistory() {
local cmd local cmd
cmd=$(fc -l 1 | \ cmd=$(fc -il 1 | \
sed 's/^[ ]*[0-9]*[ ]*//' | \ 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 \ fzf \
--ignore-case \ --ignore-case \
--scheme=history \ --scheme=history \
@ -103,8 +106,11 @@ fzfhistory() {
--tiebreak=begin,index \ --tiebreak=begin,index \
--height="$((${LINES}/4))" \ --height="$((${LINES}/4))" \
--query="${BUFFER}" \ --query="${BUFFER}" \
--preview="echo {} | sed 's/\\\n/\\n/g' | highlight -O ansi -S zsh" \ --delimiter=$'\t' \
--preview-window=wrap:30%:50% | sed 's/\\n/\n/g') --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 if [[ -n "${cmd}" ]]; then
BUFFER="${cmd}" BUFFER="${cmd}"