2015-03-13 04:08:42 +00:00
|
|
|
# Key bindings
|
|
|
|
# ------------
|
|
|
|
function fzf_key_bindings
|
|
|
|
# Due to a bug of fish, we cannot use command substitution,
|
|
|
|
# so we use temporary file instead
|
|
|
|
if [ -z "$TMPDIR" ]
|
|
|
|
set -g TMPDIR /tmp
|
|
|
|
end
|
|
|
|
|
|
|
|
function __fzf_escape
|
|
|
|
while read item
|
|
|
|
echo -n (echo -n "$item" | sed -E 's/([ "$~'\''([{<>})])/\\\\\\1/g')' '
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function __fzf_ctrl_t
|
2015-06-25 16:00:58 +00:00
|
|
|
set -q FZF_CTRL_T_COMMAND; or set -l FZF_CTRL_T_COMMAND "
|
|
|
|
command find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
|
2015-04-22 05:33:03 +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-"
|
2015-08-29 18:09:10 +00:00
|
|
|
eval "$FZF_CTRL_T_COMMAND | "(__fzfcmd)" -m > $TMPDIR/fzf.result"
|
2016-01-13 16:09:16 +00:00
|
|
|
and sleep 0
|
2015-04-21 15:30:09 +00:00
|
|
|
and commandline -i (cat $TMPDIR/fzf.result | __fzf_escape)
|
|
|
|
commandline -f repaint
|
2015-03-13 04:08:42 +00:00
|
|
|
rm -f $TMPDIR/fzf.result
|
|
|
|
end
|
|
|
|
|
|
|
|
function __fzf_ctrl_r
|
2016-03-22 18:00:20 +00:00
|
|
|
history | eval (__fzfcmd) +s +m --tiebreak=index --toggle-sort=ctrl-r $FZF_CTRL_R_OPTS > $TMPDIR/fzf.result
|
2015-03-13 04:08:42 +00:00
|
|
|
and commandline (cat $TMPDIR/fzf.result)
|
|
|
|
commandline -f repaint
|
|
|
|
rm -f $TMPDIR/fzf.result
|
|
|
|
end
|
|
|
|
|
|
|
|
function __fzf_alt_c
|
2015-11-07 15:11:46 +00:00
|
|
|
set -q FZF_ALT_C_COMMAND; or set -l 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-"
|
2015-03-13 04:08:42 +00:00
|
|
|
# Fish hangs if the command before pipe redirects (2> /dev/null)
|
2015-11-07 15:11:46 +00:00
|
|
|
eval "$FZF_ALT_C_COMMAND | "(__fzfcmd)" +m > $TMPDIR/fzf.result"
|
2015-03-13 04:08:42 +00:00
|
|
|
[ (cat $TMPDIR/fzf.result | wc -l) -gt 0 ]
|
|
|
|
and cd (cat $TMPDIR/fzf.result)
|
|
|
|
commandline -f repaint
|
|
|
|
rm -f $TMPDIR/fzf.result
|
|
|
|
end
|
|
|
|
|
2015-04-21 15:55:39 +00:00
|
|
|
function __fzfcmd
|
|
|
|
set -q FZF_TMUX; or set FZF_TMUX 1
|
|
|
|
|
|
|
|
if [ $FZF_TMUX -eq 1 ]
|
|
|
|
if set -q FZF_TMUX_HEIGHT
|
|
|
|
echo "fzf-tmux -d$FZF_TMUX_HEIGHT"
|
|
|
|
else
|
|
|
|
echo "fzf-tmux -d40%"
|
|
|
|
end
|
2015-03-13 04:08:42 +00:00
|
|
|
else
|
2015-04-21 15:55:39 +00:00
|
|
|
echo "fzf"
|
2015-03-13 04:08:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
bind \ct '__fzf_ctrl_t'
|
|
|
|
bind \cr '__fzf_ctrl_r'
|
|
|
|
bind \ec '__fzf_alt_c'
|
2015-03-30 21:10:47 +00:00
|
|
|
|
|
|
|
if bind -M insert > /dev/null 2>&1
|
|
|
|
bind -M insert \ct '__fzf_ctrl_t'
|
|
|
|
bind -M insert \cr '__fzf_ctrl_r'
|
|
|
|
bind -M insert \ec '__fzf_alt_c'
|
|
|
|
end
|
2015-03-13 04:08:42 +00:00
|
|
|
end
|
|
|
|
|