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() {
|
2017-02-18 11:33:13 -05:00
|
|
|
local cmd="${FZF_CTRL_T_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
|
2015-03-13 00:08:42 -04:00
|
|
|
-o -type f -print \
|
|
|
|
-o -type d -print \
|
2016-12-23 22:53:07 -05:00
|
|
|
-o -type l -print 2> /dev/null | cut -b3-"}"
|
2016-07-11 04:47:41 -04:00
|
|
|
setopt localoptions pipefail 2> /dev/null
|
2017-01-15 02:15:51 -05:00
|
|
|
eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS" $(__fzfcmd) -m "$@" | 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
|
|
|
}
|
|
|
|
|
2017-01-07 11:30:31 -05:00
|
|
|
__fzf_use_tmux__() {
|
|
|
|
[ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ]
|
|
|
|
}
|
|
|
|
|
2015-04-21 11:55:39 -04:00
|
|
|
__fzfcmd() {
|
2017-01-07 11:30:31 -05:00
|
|
|
__fzf_use_tmux__ &&
|
2017-01-15 02:15:51 -05:00
|
|
|
echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
|
2015-04-21 11:55:39 -04:00
|
|
|
}
|
|
|
|
|
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() {
|
2017-02-18 11:33:13 -05:00
|
|
|
local cmd="${FZF_ALT_C_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
|
2017-02-16 03:18:01 -05:00
|
|
|
-o -type d -print 2> /dev/null | cut -b3-"}"
|
2017-03-03 04:57:22 -05:00
|
|
|
setopt localoptions pipefail 2> /dev/null
|
2017-02-09 00:05:02 -05:00
|
|
|
local dir="$(eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS" $(__fzfcmd) +m)"
|
|
|
|
if [[ -z "$dir" ]]; then
|
|
|
|
zle redisplay
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
cd "$dir"
|
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
|
2017-03-03 05:09:29 -05:00
|
|
|
setopt localoptions noglobsubst noposixbuiltins pipefail 2> /dev/null
|
2017-01-15 02:15:51 -05:00
|
|
|
selected=( $(fc -l 1 |
|
2017-03-02 22:20:01 -05:00
|
|
|
FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS --tac -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS --query=${(q)LBUFFER} +m" $(__fzfcmd)) )
|
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
|