2017-01-30 22:04:29 +00:00
|
|
|
__fzf_use_tmux__() {
|
|
|
|
[ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
__fzfcmd() {
|
|
|
|
__fzf_use_tmux__ &&
|
|
|
|
echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
|
|
|
|
}
|
|
|
|
|
|
|
|
# CTRL-R - Paste the selected command from history into the command line
|
|
|
|
fzf-history-widget() {
|
|
|
|
local selected num
|
|
|
|
setopt localoptions noglobsubst pipefail 2> /dev/null
|
|
|
|
selected=( $(fc -l 1 |
|
2017-02-21 20:18:15 +00:00
|
|
|
FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS +s --tac -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS --query=${(q)LBUFFER} +m" $(__fzfcmd)) )
|
2017-01-30 22:04:29 +00:00
|
|
|
local ret=$?
|
|
|
|
if [ -n "$selected" ]; then
|
|
|
|
num=$selected[1]
|
|
|
|
if [ -n "$num" ]; then
|
|
|
|
zle vi-fetch-history -n $num
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
zle redisplay
|
|
|
|
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
|
|
|
return $ret
|
|
|
|
}
|
2017-02-21 20:18:15 +00:00
|
|
|
|
2017-01-30 22:04:29 +00:00
|
|
|
zle -N fzf-history-widget
|
|
|
|
bindkey '^R' fzf-history-widget
|