Files
fzf/shell/key-bindings.fish
T

75 lines
2.4 KiB
Fish
Raw Normal View History

2015-03-13 13:08:42 +09:00
# Key bindings
# ------------
function fzf_key_bindings
2016-12-14 12:07:27 +05:30
# Store last token in $dir as root for the 'find' command
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 13:08:42 +09:00
end
2016-12-14 12:07:27 +05:30
# Some 'find' versions print undesired duplicated slashes if the path ends with slashes.
set dir (string replace --regex '(.)/+$' '$1' "$dir")
2015-03-13 13:08:42 +09:00
2016-12-14 12:07:27 +05:30
# "-path \$dir'*/\\.*'" matches hidden files/folders inside $dir but not
# $dir itself, even if hidden.
2015-06-26 01:00:58 +09:00
set -q FZF_CTRL_T_COMMAND; or set -l FZF_CTRL_T_COMMAND "
command find -L \$dir -mindepth 1 \\( -path \$dir'*/\\.*' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \
2016-12-14 12:07:27 +05:30
-o -type f -print \
-o -type d -print \
-o -type l -print 2> /dev/null | sed 's#^\./##'"
2016-12-14 12:07:27 +05:30
eval "$FZF_CTRL_T_COMMAND | "(__fzfcmd)" -m $FZF_CTRL_T_OPTS" | while read -l r; set result $result $r; end
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-22 00:30:09 +09:00
commandline -f repaint
2015-03-13 13:08:42 +09:00
end
2016-12-14 12:07:27 +05:30
function fzf-history-widget -d "Show command history"
2017-01-08 01:30:31 +09:00
history | eval (__fzfcmd) +s +m --no-reverse --tiebreak=index $FZF_CTRL_R_OPTS -q '(commandline)' | read -l result
2016-12-14 12:07:27 +05:30
and commandline -- $result
2015-03-13 13:08:42 +09:00
commandline -f repaint
end
2016-12-14 12:07:27 +05:30
function fzf-cd-widget -d "Change directory"
set -q FZF_ALT_C_COMMAND; or set -l FZF_ALT_C_COMMAND "
2016-12-14 12:07:27 +05:30
command find -L . \\( -path '*/\\.*' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \
-o -type d -print 2> /dev/null | sed 1d | cut -b3-"
eval "$FZF_ALT_C_COMMAND | "(__fzfcmd)" +m $FZF_ALT_C_OPTS" | read -l result
[ "$result" ]; and cd $result
2015-03-13 13:08:42 +09:00
commandline -f repaint
end
function __fzfcmd
2017-01-08 01:30:31 +09:00
set -q FZF_TMUX; or set FZF_TMUX 0
set -q FZF_TMUX_HEIGHT; or set FZF_TMUX_HEIGHT 40%
if [ $FZF_TMUX -eq 1 ]
2017-01-08 01:30:31 +09:00
echo "fzf-tmux -d$FZF_TMUX_HEIGHT"
2015-03-13 13:08:42 +09:00
else
2017-01-08 01:30:31 +09:00
echo "fzf --height $FZF_TMUX_HEIGHT --reverse"
2015-03-13 13:08:42 +09:00
end
end
bind \ct fzf-file-widget
bind \cr fzf-history-widget
bind \ec fzf-cd-widget
if bind -M insert > /dev/null 2>&1
bind -M insert \ct fzf-file-widget
bind -M insert \cr fzf-history-widget
bind -M insert \ec fzf-cd-widget
end
2015-03-13 13:08:42 +09:00
end