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() {
|
2015-11-07 15:11:46 +00:00
|
|
|
local cmd="${FZF_CTRL_T_COMMAND:-"command find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
|
2015-03-13 04:08:42 +00:00
|
|
|
-o -type f -print \
|
|
|
|
-o -type d -print \
|
2015-06-25 16:00:58 +00:00
|
|
|
-o -type l -print 2> /dev/null | sed 1d | cut -b3-"}"
|
|
|
|
eval "$cmd" | $(__fzfcmd) -m | while read item; do
|
2015-03-13 04:08:42 +00:00
|
|
|
printf '%q ' "$item"
|
|
|
|
done
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
2015-04-21 15:55:39 +00:00
|
|
|
__fzfcmd() {
|
|
|
|
[ ${FZF_TMUX:-1} -eq 1 ] && echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
|
|
|
|
}
|
|
|
|
|
2015-04-21 15:30:09 +00:00
|
|
|
fzf-file-widget() {
|
|
|
|
LBUFFER="${LBUFFER}$(__fsel)"
|
|
|
|
zle redisplay
|
|
|
|
}
|
2015-03-13 04:08:42 +00:00
|
|
|
zle -N fzf-file-widget
|
|
|
|
bindkey '^T' fzf-file-widget
|
|
|
|
|
|
|
|
# ALT-C - cd into the selected directory
|
|
|
|
fzf-cd-widget() {
|
2015-11-07 15:11:46 +00: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-"}"
|
|
|
|
cd "${$(eval "$cmd" | $(__fzfcmd) +m):-.}"
|
2015-03-13 04:08:42 +00:00
|
|
|
zle reset-prompt
|
|
|
|
}
|
|
|
|
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
|
2015-11-09 03:06:10 +00:00
|
|
|
selected=( $(fc -l 1 | $(__fzfcmd) +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r -q "${LBUFFER//$/\\$}") )
|
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
|
|
|
|
}
|
|
|
|
zle -N fzf-history-widget
|
|
|
|
bindkey '^R' fzf-history-widget
|
|
|
|
|
|
|
|
fi
|
|
|
|
|