fzf Ctrl-R history

Changed files
+21
modules
personal
+21
modules/personal/zsh.cfg
···
bindkey -M vicmd '\ec' fzf-cd-widget
bindkey -M viins '\ec' fzf-cd-widget
wait-ssh() {
while ! timeout 1 ping $1 -c 1; do sleep 1; done; ssh $1
}
···
bindkey -M vicmd '\ec' fzf-cd-widget
bindkey -M viins '\ec' fzf-cd-widget
+
# CTRL-R - Paste the selected command from history into the command line
+
fzf-history-widget() {
+
local selected num
+
setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases 2> /dev/null
+
selected=( $(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} +m" $(__fzfcmd)) )
+
local ret=$?
+
if [ -n "$selected" ]; then
+
num=$selected[1]
+
if [ -n "$num" ]; then
+
zle vi-fetch-history -n $num
+
fi
+
fi
+
zle reset-prompt
+
return $ret
+
}
+
zle -N fzf-history-widget
+
bindkey -M emacs '^R' fzf-history-widget
+
bindkey -M vicmd '^R' fzf-history-widget
+
bindkey -M viins '^R' fzf-history-widget
+
wait-ssh() {
while ! timeout 1 ping $1 -c 1; do sleep 1; done; ssh $1
}