2015-03-13 07:08:42 +03: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
|
|
|
|
|
2016-04-24 07:55:48 +03:00
|
|
|
function fzf-file-widget
|
2015-06-25 19:00:58 +03:00
|
|
|
set -q FZF_CTRL_T_COMMAND; or set -l FZF_CTRL_T_COMMAND "
|
2016-11-14 19:51:25 +03:00
|
|
|
command find -L . \\( -path '*/\\.*' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
|
2015-04-22 08:33:03 +03:00
|
|
|
-o -type f -print \
|
|
|
|
-o -type d -print \
|
2015-06-25 19:00:58 +03:00
|
|
|
-o -type l -print 2> /dev/null | sed 1d | cut -b3-"
|
2016-06-12 14:37:17 +03:00
|
|
|
eval "$FZF_CTRL_T_COMMAND | "(__fzfcmd)" -m $FZF_CTRL_T_OPTS > $TMPDIR/fzf.result"
|
2016-04-23 22:51:35 +03:00
|
|
|
and for i in (seq 20); commandline -i (cat $TMPDIR/fzf.result | __fzf_escape) 2> /dev/null; and break; sleep 0.1; end
|
2015-04-21 18:30:09 +03:00
|
|
|
commandline -f repaint
|
2015-03-13 07:08:42 +03:00
|
|
|
rm -f $TMPDIR/fzf.result
|
|
|
|
end
|
|
|
|
|
2016-04-24 07:55:48 +03:00
|
|
|
function fzf-history-widget
|
2016-10-11 18:42:31 +03:00
|
|
|
history | eval (__fzfcmd) +s +m --tiebreak=index --toggle-sort=ctrl-r $FZF_CTRL_R_OPTS -q '(commandline)' > $TMPDIR/fzf.result
|
|
|
|
and commandline -- (cat $TMPDIR/fzf.result)
|
2015-03-13 07:08:42 +03:00
|
|
|
commandline -f repaint
|
|
|
|
rm -f $TMPDIR/fzf.result
|
|
|
|
end
|
|
|
|
|
2016-04-24 07:55:48 +03:00
|
|
|
function fzf-cd-widget
|
2015-11-07 18:11:46 +03:00
|
|
|
set -q FZF_ALT_C_COMMAND; or set -l FZF_ALT_C_COMMAND "
|
2016-11-14 19:51:25 +03:00
|
|
|
command find -L . \\( -path '*/\\.*' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
|
2015-11-07 18:11:46 +03:00
|
|
|
-o -type d -print 2> /dev/null | sed 1d | cut -b3-"
|
2015-03-13 07:08:42 +03:00
|
|
|
# Fish hangs if the command before pipe redirects (2> /dev/null)
|
2016-06-12 14:37:17 +03:00
|
|
|
eval "$FZF_ALT_C_COMMAND | "(__fzfcmd)" +m $FZF_ALT_C_OPTS > $TMPDIR/fzf.result"
|
2015-03-13 07:08:42 +03: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 18:55:39 +03: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 07:08:42 +03:00
|
|
|
else
|
2015-04-21 18:55:39 +03:00
|
|
|
echo "fzf"
|
2015-03-13 07:08:42 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-24 07:55:48 +03:00
|
|
|
bind \ct fzf-file-widget
|
|
|
|
bind \cr fzf-history-widget
|
|
|
|
bind \ec fzf-cd-widget
|
2015-03-31 00:10:47 +03:00
|
|
|
|
|
|
|
if bind -M insert > /dev/null 2>&1
|
2016-04-24 07:55:48 +03:00
|
|
|
bind -M insert \ct fzf-file-widget
|
|
|
|
bind -M insert \cr fzf-history-widget
|
|
|
|
bind -M insert \ec fzf-cd-widget
|
2015-03-31 00:10:47 +03:00
|
|
|
end
|
2015-03-13 07:08:42 +03:00
|
|
|
end
|
|
|
|
|