aboutsummaryrefslogtreecommitdiff
path: root/files/.zsh/rc/S90_fzf
diff options
context:
space:
mode:
Diffstat (limited to 'files/.zsh/rc/S90_fzf')
-rw-r--r--files/.zsh/rc/S90_fzf42
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
+)"