Files
fzf/shell/key-bindings.zsh
T

78 lines
2.4 KiB
Bash
Raw Normal View History

2015-03-13 13:08:42 +09:00
# Key bindings
# ------------
2015-10-01 15:18:10 -04:00
if [[ $- == *i* ]]; then
2015-03-13 13:08:42 +09:00
# CTRL-T - Paste the selected file path(s) into the command line
__fsel() {
2017-02-19 01:33:13 +09: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 13:08:42 +09:00
-o -type f -print \
-o -type d -print \
-o -type l -print 2> /dev/null | cut -b3-"}"
setopt localoptions pipefail 2> /dev/null
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-25 00:53:11 +09:00
echo -n "${(q)item} "
2015-03-13 13:08:42 +09:00
done
2016-06-16 01:03:48 +02:00
local ret=$?
2015-03-13 13:08:42 +09:00
echo
2016-06-16 01:03:48 +02:00
return $ret
2015-03-13 13:08:42 +09:00
}
2017-01-08 01:30:31 +09:00
__fzf_use_tmux__() {
[ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ]
}
__fzfcmd() {
2017-01-08 01:30:31 +09:00
__fzf_use_tmux__ &&
echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
}
2015-04-22 00:30:09 +09:00
fzf-file-widget() {
LBUFFER="${LBUFFER}$(__fsel)"
2016-06-16 01:03:48 +02:00
local ret=$?
2015-04-22 00:30:09 +09:00
zle redisplay
2016-07-04 12:13:02 +02:00
typeset -f zle-line-init >/dev/null && zle zle-line-init
2016-06-16 01:03:48 +02:00
return $ret
2015-04-22 00:30:09 +09:00
}
2015-03-13 13:08:42 +09:00
zle -N fzf-file-widget
bindkey '^T' fzf-file-widget
# ALT-C - cd into the selected directory
fzf-cd-widget() {
2017-02-19 01:33:13 +09: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 \
-o -type d -print 2> /dev/null | cut -b3-"}"
setopt localoptions pipefail 2> /dev/null
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-16 01:03:48 +02:00
local ret=$?
2015-03-13 13:08:42 +09:00
zle reset-prompt
2016-07-04 12:13:02 +02:00
typeset -f zle-line-init >/dev/null && zle zle-line-init
2016-06-16 01:03:48 +02:00
return $ret
2015-03-13 13:08:42 +09: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() {
local selected num
setopt localoptions noglobsubst noposixbuiltins pipefail 2> /dev/null
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-16 01:03:48 +02:00
local ret=$?
2015-11-03 17:52:44 -08:00
if [ -n "$selected" ]; then
num=$selected[1]
if [ -n "$num" ]; then
zle vi-fetch-history -n $num
fi
2015-03-13 13:08:42 +09:00
fi
zle redisplay
2016-07-04 12:13:02 +02:00
typeset -f zle-line-init >/dev/null && zle zle-line-init
2016-06-16 01:03:48 +02:00
return $ret
2015-03-13 13:08:42 +09:00
}
zle -N fzf-history-widget
bindkey '^R' fzf-history-widget
fi