2015-03-13 00:08:42 -04:00
|
|
|
# Key bindings
|
|
|
|
# ------------
|
|
|
|
# CTRL-T - Paste the selected file path(s) into the command line
|
|
|
|
__fsel() {
|
|
|
|
command find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
|
|
|
|
-o -type f -print \
|
|
|
|
-o -type d -print \
|
2015-04-21 11:55:39 -04:00
|
|
|
-o -type l -print 2> /dev/null | sed 1d | cut -b3- | $(__fzfcmd) -m | while read item; do
|
2015-03-13 00:08:42 -04:00
|
|
|
printf '%q ' "$item"
|
|
|
|
done
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
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-03-13 00:08:42 -04:00
|
|
|
if [[ $- =~ i ]]; then
|
|
|
|
|
2015-04-21 11:30:09 -04:00
|
|
|
fzf-file-widget() {
|
|
|
|
LBUFFER="${LBUFFER}$(__fsel)"
|
|
|
|
zle redisplay
|
|
|
|
}
|
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() {
|
|
|
|
cd "${$(command find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
|
2015-04-21 11:55:39 -04:00
|
|
|
-o -type d -print 2> /dev/null | sed 1d | cut -b3- | $(__fzfcmd) +m):-.}"
|
2015-03-13 00:08:42 -04: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() {
|
|
|
|
local selected
|
2015-04-21 11:55:39 -04:00
|
|
|
if selected=$(fc -l 1 | $(__fzfcmd) +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r -q "$LBUFFER"); then
|
2015-03-13 00:08:42 -04:00
|
|
|
num=$(echo "$selected" | head -1 | awk '{print $1}' | sed 's/[^0-9]//g')
|
|
|
|
LBUFFER=!$num
|
|
|
|
zle expand-history
|
|
|
|
fi
|
|
|
|
zle redisplay
|
|
|
|
}
|
|
|
|
zle -N fzf-history-widget
|
|
|
|
bindkey '^R' fzf-history-widget
|
|
|
|
|
|
|
|
fi
|
|
|
|
|