2015-03-13 04:08:42 +00:00
|
|
|
# Key bindings
|
|
|
|
# ------------
|
|
|
|
function fzf_key_bindings
|
|
|
|
|
2017-02-16 08:18:01 +00:00
|
|
|
# Store current token in $dir as root for the 'find' command
|
2016-12-14 06:37:27 +00:00
|
|
|
function fzf-file-widget -d "List files and folders"
|
|
|
|
set -l dir (commandline -t)
|
|
|
|
# The commandline token might be escaped, we need to unescape it.
|
|
|
|
set dir (eval "printf '%s' $dir")
|
|
|
|
if [ ! -d "$dir" ]
|
|
|
|
set dir .
|
2015-03-13 04:08:42 +00:00
|
|
|
end
|
2016-12-14 06:37:27 +00:00
|
|
|
# Some 'find' versions print undesired duplicated slashes if the path ends with slashes.
|
|
|
|
set dir (string replace --regex '(.)/+$' '$1' "$dir")
|
2015-03-13 04:08:42 +00:00
|
|
|
|
2016-12-14 06:37:27 +00:00
|
|
|
# "-path \$dir'*/\\.*'" matches hidden files/folders inside $dir but not
|
|
|
|
# $dir itself, even if hidden.
|
2015-06-25 16:00:58 +00:00
|
|
|
set -q FZF_CTRL_T_COMMAND; or set -l FZF_CTRL_T_COMMAND "
|
2017-02-18 16:33:13 +00:00
|
|
|
command find -L \$dir -mindepth 1 \\( -path \$dir'*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \
|
2016-12-14 06:37:27 +00:00
|
|
|
-o -type f -print \
|
|
|
|
-o -type d -print \
|
2017-02-16 08:18:01 +00:00
|
|
|
-o -type l -print 2> /dev/null | cut -b3-"
|
2016-12-14 06:37:27 +00:00
|
|
|
|
2017-01-15 07:15:51 +00:00
|
|
|
set -q FZF_TMUX_HEIGHT; or set FZF_TMUX_HEIGHT 40%
|
|
|
|
begin
|
|
|
|
set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT --reverse $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS"
|
|
|
|
eval "$FZF_CTRL_T_COMMAND | "(__fzfcmd)" -m" | while read -l r; set result $result $r; end
|
|
|
|
end
|
2016-12-14 06:37:27 +00:00
|
|
|
if [ -z "$result" ]
|
|
|
|
commandline -f repaint
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if [ "$dir" != . ]
|
|
|
|
# Remove last token from commandline.
|
|
|
|
commandline -t ""
|
|
|
|
end
|
|
|
|
for i in $result
|
|
|
|
commandline -it -- (string escape $i)
|
|
|
|
commandline -it -- ' '
|
|
|
|
end
|
2015-04-21 15:30:09 +00:00
|
|
|
commandline -f repaint
|
2015-03-13 04:08:42 +00:00
|
|
|
end
|
|
|
|
|
2016-12-14 06:37:27 +00:00
|
|
|
function fzf-history-widget -d "Show command history"
|
2017-01-15 07:15:51 +00:00
|
|
|
set -q FZF_TMUX_HEIGHT; or set FZF_TMUX_HEIGHT 40%
|
|
|
|
begin
|
2017-01-26 02:54:08 +00:00
|
|
|
set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT $FZF_DEFAULT_OPTS +s --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS +m"
|
2017-01-15 07:15:51 +00:00
|
|
|
history | eval (__fzfcmd) -q '(commandline)' | read -l result
|
|
|
|
and commandline -- $result
|
|
|
|
end
|
2015-03-13 04:08:42 +00:00
|
|
|
commandline -f repaint
|
|
|
|
end
|
|
|
|
|
2016-12-14 06:37:27 +00:00
|
|
|
function fzf-cd-widget -d "Change directory"
|
2015-11-07 15:11:46 +00:00
|
|
|
set -q FZF_ALT_C_COMMAND; or set -l FZF_ALT_C_COMMAND "
|
2017-02-18 16:33:13 +00:00
|
|
|
command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \
|
2017-02-16 08:18:01 +00:00
|
|
|
-o -type d -print 2> /dev/null | cut -b3-"
|
2017-01-15 07:15:51 +00:00
|
|
|
set -q FZF_TMUX_HEIGHT; or set FZF_TMUX_HEIGHT 40%
|
|
|
|
begin
|
|
|
|
set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT --reverse $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS"
|
|
|
|
eval "$FZF_ALT_C_COMMAND | "(__fzfcmd)" +m" | read -l result
|
|
|
|
[ "$result" ]; and cd $result
|
|
|
|
end
|
2015-03-13 04:08:42 +00:00
|
|
|
commandline -f repaint
|
|
|
|
end
|
|
|
|
|
2015-04-21 15:55:39 +00:00
|
|
|
function __fzfcmd
|
2017-01-07 16:30:31 +00:00
|
|
|
set -q FZF_TMUX; or set FZF_TMUX 0
|
|
|
|
set -q FZF_TMUX_HEIGHT; or set FZF_TMUX_HEIGHT 40%
|
2015-04-21 15:55:39 +00:00
|
|
|
if [ $FZF_TMUX -eq 1 ]
|
2017-01-07 16:30:31 +00:00
|
|
|
echo "fzf-tmux -d$FZF_TMUX_HEIGHT"
|
2015-03-13 04:08:42 +00:00
|
|
|
else
|
2017-01-15 07:15:51 +00:00
|
|
|
echo "fzf"
|
2015-03-13 04:08:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-24 04:55:48 +00:00
|
|
|
bind \ct fzf-file-widget
|
|
|
|
bind \cr fzf-history-widget
|
|
|
|
bind \ec fzf-cd-widget
|
2015-03-30 21:10:47 +00:00
|
|
|
|
|
|
|
if bind -M insert > /dev/null 2>&1
|
2016-04-24 04:55:48 +00:00
|
|
|
bind -M insert \ct fzf-file-widget
|
|
|
|
bind -M insert \cr fzf-history-widget
|
|
|
|
bind -M insert \ec fzf-cd-widget
|
2015-03-30 21:10:47 +00:00
|
|
|
end
|
2015-03-13 04:08:42 +00:00
|
|
|
end
|