2015-03-13 04:08:42 +00:00
|
|
|
# Key bindings
|
|
|
|
# ------------
|
2015-10-01 19:18:10 +00:00
|
|
|
if [[ $- == *i* ]]; then
|
2015-06-25 15:14:36 +00:00
|
|
|
|
2015-03-13 04:08:42 +00:00
|
|
|
# CTRL-T - Paste the selected file path(s) into the command line
|
|
|
|
__fsel() {
|
2017-02-18 16:33:13 +00: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 04:08:42 +00:00
|
|
|
-o -type f -print \
|
|
|
|
-o -type d -print \
|
2016-12-24 03:53:07 +00:00
|
|
|
-o -type l -print 2> /dev/null | cut -b3-"}"
|
2016-07-11 08:47:41 +00:00
|
|
|
setopt localoptions pipefail 2> /dev/null
|
2017-01-15 07:15:51 +00: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 15:53:11 +00:00
|
|
|
echo -n "${(q)item} "
|
2015-03-13 04:08:42 +00:00
|
|
|
done
|
2016-06-15 23:03:48 +00:00
|
|
|
local ret=$?
|
2015-03-13 04:08:42 +00:00
|
|
|
echo
|
2016-06-15 23:03:48 +00:00
|
|
|
return $ret
|
2015-03-13 04:08:42 +00:00
|
|
|
}
|
|
|
|
|
2017-01-07 16:30:31 +00:00
|
|
|
__fzf_use_tmux__() {
|
|
|
|
[ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ]
|
|
|
|
}
|
|
|
|
|
2015-04-21 15:55:39 +00:00
|
|
|
__fzfcmd() {
|
2017-01-07 16:30:31 +00:00
|
|
|
__fzf_use_tmux__ &&
|
2017-01-15 07:15:51 +00:00
|
|
|
echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
|
2015-04-21 15:55:39 +00:00
|
|
|
}
|
|
|
|
|
2015-04-21 15:30:09 +00:00
|
|
|
fzf-file-widget() {
|
|
|
|
LBUFFER="${LBUFFER}$(__fsel)"
|
2016-06-15 23:03:48 +00:00
|
|
|
local ret=$?
|
2015-04-21 15:30:09 +00:00
|
|
|
zle redisplay
|
2016-07-04 10:13:02 +00:00
|
|
|
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
2016-06-15 23:03:48 +00:00
|
|
|
return $ret
|
2015-04-21 15:30:09 +00:00
|
|
|
}
|
2015-03-13 04:08:42 +00:00
|
|
|
zle -N fzf-file-widget
|
|
|
|
bindkey '^T' fzf-file-widget
|
|
|
|
|
2017-11-14 03:43:52 +00:00
|
|
|
# Ensure precmds are run after cd
|
|
|
|
fzf-redraw-prompt() {
|
|
|
|
local precmd
|
|
|
|
for precmd in $precmd_functions; do
|
|
|
|
$precmd
|
|
|
|
done
|
|
|
|
zle reset-prompt
|
|
|
|
}
|
|
|
|
zle -N fzf-redraw-prompt
|
|
|
|
|
2015-03-13 04:08:42 +00:00
|
|
|
# ALT-C - cd into the selected directory
|
|
|
|
fzf-cd-widget() {
|
2017-02-18 16:33:13 +00: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 08:18:01 +00:00
|
|
|
-o -type d -print 2> /dev/null | cut -b3-"}"
|
2017-03-03 09:57:22 +00:00
|
|
|
setopt localoptions pipefail 2> /dev/null
|
2017-02-09 05:05:02 +00: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 23:03:48 +00:00
|
|
|
local ret=$?
|
2017-11-14 03:43:52 +00:00
|
|
|
zle fzf-redraw-prompt
|
2016-07-04 10:13:02 +00:00
|
|
|
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
2016-06-15 23:03:48 +00:00
|
|
|
return $ret
|
2015-03-13 04:08:42 +00: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 12:55:35 +00:00
|
|
|
local selected num
|
2017-03-03 10:09:29 +00:00
|
|
|
setopt localoptions noglobsubst noposixbuiltins pipefail 2> /dev/null
|
2017-10-20 03:56:02 +00:00
|
|
|
selected=( $(fc -rl 1 |
|
|
|
|
FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS --query=${(qqq)LBUFFER} +m" $(__fzfcmd)) )
|
2016-06-15 23:03:48 +00:00
|
|
|
local ret=$?
|
2015-11-04 01:52:44 +00:00
|
|
|
if [ -n "$selected" ]; then
|
2015-06-20 22:44:27 +00:00
|
|
|
num=$selected[1]
|
2015-04-23 13:39:07 +00:00
|
|
|
if [ -n "$num" ]; then
|
2015-06-20 22:44:27 +00:00
|
|
|
zle vi-fetch-history -n $num
|
2015-04-23 13:31:23 +00:00
|
|
|
fi
|
2015-03-13 04:08:42 +00:00
|
|
|
fi
|
|
|
|
zle redisplay
|
2016-07-04 10:13:02 +00:00
|
|
|
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
2016-06-15 23:03:48 +00:00
|
|
|
return $ret
|
2015-03-13 04:08:42 +00:00
|
|
|
}
|
|
|
|
zle -N fzf-history-widget
|
|
|
|
bindkey '^R' fzf-history-widget
|
|
|
|
|
|
|
|
fi
|