diff options
| author | Anton Bobov <anton@bobov.name> | 2024-11-22 21:11:50 +0500 |
|---|---|---|
| committer | Anton Bobov <anton@bobov.name> | 2024-11-22 21:11:50 +0500 |
| commit | bfd9abb5ff4e1bbd1e240ceb344a0b1c7a7fe327 (patch) | |
| tree | c0ec83a1f65b4b94ca4aae3a17585fdc65ec9175 | |
| parent | 4a48ace97dd581f49ee00a0820001854aee1ff0e (diff) | |
zsh: Fzf history with delete
Allow to delete history entry with Ctrl+d
| -rw-r--r-- | files/.zsh/rc/S90_fzf | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/files/.zsh/rc/S90_fzf b/files/.zsh/rc/S90_fzf index eddbfdd..dbf210c 100644 --- a/files/.zsh/rc/S90_fzf +++ b/files/.zsh/rc/S90_fzf @@ -34,3 +34,45 @@ _gen_fzf_default_opts() { " } _gen_fzf_default_opts + +# +# https://github.com/junegunn/fzf/discussions/3629 +# +modified-fzf-history-widget() { + local selected + setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases no_bash_rematch 2> /dev/null + # appends the current shell history buffer to the HISTFILE + builtin fc -AI $HISTFILE + # pushes entries from the $HISTFILE onto a stack and uses this history + builtin fc -p $HISTFILE $HISTSIZE $SAVEHIST + selected="$(builtin fc -rl 1 | + awk '{ cmd=$0; sub(/^[ \t]*[0-9]+\**[ \t]+/, "", cmd); if (!seen[cmd]++) print $0 }' | + FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} ${FZF_DEFAULT_OPTS-} -n2..,.. --scheme=history --bind=ctrl-r:toggle-sort,ctrl-z:ignore ${FZF_CTRL_R_OPTS-} --query=${(qqq)LBUFFER} --multi" $(__fzfcmd))" + local ret=$? + if [[ -n $selected ]]; then + if [[ "$selected" =~ ^[[:blank:]]*[[:digit:]]+ ]]; then + builtin fc -pa "$HISTFILE" + zle vi-fetch-history -n "$MATCH" + else # selected is a custom query, not from history + LBUFFER="$selected" + fi + fi + # Read the history from the history file into the history list + builtin fc -R $HISTFILE + zle reset-prompt + return $ret +} +zle -N modified-fzf-history-widget +bindkey "^R" modified-fzf-history-widget + + +export FZF_CTRL_R_OPTS="$( + cat <<'FZF_FTW' +--bind "ctrl-d:execute-silent(zsh -ic 'builtin fc -p $HISTFILE $HISTSIZE $SAVEHIST; for i in {+1}; do ignore+=( \"${(b)history[$i]}\" );done; + HISTORY_IGNORE=\"(${(j:|:)ignore})\";builtin fc -W $HISTFILE')+reload:builtin fc -p $HISTFILE $HISTSIZE $SAVEHIST; builtin fc -rl 1 | + awk '{ cmd=$0; sub(/^[ \t]*[0-9]+\**[ \t]+/, \"\", cmd); if (!seen[cmd]++) print $0 }'" +--bind 'enter:accept-or-print-query' +--header 'enter select ยท ^d remove' +--prompt ' Global History > ' +FZF_FTW +)" |
