2015-03-13 00:08:42 -04:00
|
|
|
# Key bindings
|
|
|
|
# ------------
|
2015-10-01 15:18:10 -04:00
|
|
|
if [[ $- == *i* ]]; then
|
2015-06-25 11:14:36 -04:00
|
|
|
|
2015-03-13 00:08:42 -04:00
|
|
|
# CTRL-T - Paste the selected file path(s) into the command line
|
|
|
|
__fsel() {
|
2015-11-07 10:11:46 -05:00
|
|
|
local cmd="${FZF_CTRL_T_COMMAND:-"command find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
|
2015-03-13 00:08:42 -04:00
|
|
|
-o -type f -print \
|
|
|
|
-o -type d -print \
|
2015-06-25 12:00:58 -04:00
|
|
|
-o -type l -print 2> /dev/null | sed 1d | cut -b3-"}"
|
2016-07-11 04:47:41 -04:00
|
|
|
setopt localoptions pipefail 2> /dev/null
|
2016-06-12 07:37:17 -04:00
|
|
|
eval "$cmd | $(__fzfcmd) -m $FZF_CTRL_T_OPTS" | while read item; do
|
2016-04-24 11:53:11 -04:00
|
|
|
echo -n "${(q)item} "
|
2015-03-13 00:08:42 -04:00
|
|
|
done
|
2016-06-15 19:03:48 -04:00
|
|
|
local ret=$?
|
2015-03-13 00:08:42 -04:00
|
|
|
echo
|
2016-06-15 19:03:48 -04:00
|
|
|
return $ret
|
2015-03-13 00:08:42 -04:00
|
|
|
}
|
|
|
|
|
2015-04-21 11:55:39 -04:00
|
|
|
__fzfcmd() {
|
|
|
|
[ ${FZF_TMUX:-1} -eq 1 ] && echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
|
|
|
|
}
|
|
|
|
|
2015-04-21 11:30:09 -04:00
|
|
|
fzf-file-widget() {
|
|
|
|
LBUFFER="${LBUFFER}$(__fsel)"
|
2016-06-15 19:03:48 -04:00
|
|
|
local ret=$?
|
2015-04-21 11:30:09 -04:00
|
|
|
zle redisplay
|
2016-07-04 06:13:02 -04:00
|
|
|
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
2016-06-15 19:03:48 -04:00
|
|
|
return $ret
|
2015-04-21 11:30:09 -04:00
|
|
|
}
|
2015-03-13 00:08:42 -04:00
|
|
|
zle -N fzf-file-widget
|
|
|
|
bindkey '^T' fzf-file-widget
|
|
|
|
|
|
|
|
# ALT-C - cd into the selected directory
|
|
|
|
fzf-cd-widget() {
|
2015-11-07 10:11:46 -05:00
|
|
|
local cmd="${FZF_ALT_C_COMMAND:-"command find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
|
|
|
|
-o -type d -print 2> /dev/null | sed 1d | cut -b3-"}"
|
2016-07-11 04:47:41 -04:00
|
|
|
setopt localoptions pipefail 2> /dev/null
|
2016-06-12 07:37:17 -04:00
|
|
|
cd "${$(eval "$cmd | $(__fzfcmd) +m $FZF_ALT_C_OPTS"):-.}"
|
2016-06-15 19:03:48 -04:00
|
|
|
local ret=$?
|
2015-03-13 00:08:42 -04:00
|
|
|
zle reset-prompt
|
2016-07-04 06:13:02 -04:00
|
|
|
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
2016-06-15 19:03:48 -04:00
|
|
|
return $ret
|
2015-03-13 00:08:42 -04:00
|
|
|
}
|
|
|
|
zle -N fzf-cd-widget
|
|
|
|
bindkey '\ec' fzf-cd-widget
|
|
|
|
|
|
|
|
# CTRL-R - Paste the selected command from history into the command line
|
|
|
|
fzf-history-widget() {
|
2015-11-04 07:55:35 -05:00
|
|
|
local selected num
|
2016-07-11 04:47:41 -04:00
|
|
|
setopt localoptions noglobsubst pipefail 2> /dev/null
|
2016-06-07 12:30:26 -04:00
|
|
|
selected=( $(fc -l 1 | eval "$(__fzfcmd) +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r $FZF_CTRL_R_OPTS -q ${(q)LBUFFER}") )
|
2016-06-15 19:03:48 -04:00
|
|
|
local ret=$?
|
2015-11-03 20:52:44 -05:00
|
|
|
if [ -n "$selected" ]; then
|
2015-06-20 18:44:27 -04:00
|
|
|
num=$selected[1]
|
2015-04-23 09:39:07 -04:00
|
|
|
if [ -n "$num" ]; then
|
2015-06-20 18:44:27 -04:00
|
|
|
zle vi-fetch-history -n $num
|
2015-04-23 09:31:23 -04:00
|
|
|
fi
|
2015-03-13 00:08:42 -04:00
|
|
|
fi
|
|
|
|
zle redisplay
|
2016-07-04 06:13:02 -04:00
|
|
|
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
2016-06-15 19:03:48 -04:00
|
|
|
return $ret
|
2015-03-13 00:08:42 -04:00
|
|
|
}
|
|
|
|
zle -N fzf-history-widget
|
|
|
|
bindkey '^R' fzf-history-widget
|
|
|
|
|
|
|
|
fi
|
|
|
|
|