2016-10-13 11:09:04 +02:00
|
|
|
fzf_key_bindings
|
|
|
|
bind \cT transpose-chars
|
2016-11-27 05:01:20 +01:00
|
|
|
bind \e\ct __fzf-file-widget
|
2016-10-13 11:09:04 +02:00
|
|
|
bind \ec capitalize-word
|
2016-11-27 05:01:20 +01:00
|
|
|
bind \eC __fzf-cd-widget
|
2016-10-13 11:09:04 +02:00
|
|
|
|
2016-10-14 13:47:06 +02:00
|
|
|
function __fzf-select -d 'fzf commandline and print unescaped selection back to commandline'
|
2016-10-19 07:22:19 +02:00
|
|
|
set -l cmd (commandline -j)
|
|
|
|
[ "$cmd" ]; or return
|
2016-11-27 05:01:20 +01:00
|
|
|
eval $cmd | eval (__fzfcmd) -m --tiebreak=index --select-1 --exit-0 | string join ' ' | read -l result
|
2016-10-19 07:22:19 +02:00
|
|
|
[ "$result" ]; and commandline -j -- $result
|
2016-10-13 11:09:04 +02:00
|
|
|
commandline -f repaint
|
|
|
|
end
|
2016-10-13 15:12:55 +02:00
|
|
|
bind \e\cm __fzf-select
|
2016-10-13 11:09:04 +02:00
|
|
|
|
2016-10-14 13:47:06 +02:00
|
|
|
function __fzf-complete -d 'fzf completion and print selection back to commandline'
|
2016-10-18 09:11:10 +02:00
|
|
|
set -l complist (complete -C(commandline -c))
|
2016-10-14 12:37:43 +02:00
|
|
|
set -l result
|
2016-11-27 05:01:20 +01:00
|
|
|
string join -- \n $complist | sort | eval (__fzfcmd) -m --tiebreak=index --select-1 --exit-0 --header '(commandline)' | cut -f1 | while read -l r; set result $result $r; end
|
2016-10-14 12:37:43 +02:00
|
|
|
|
2016-10-14 15:20:10 +02:00
|
|
|
for i in (seq (count $result))
|
|
|
|
set -l r $result[$i]
|
2016-10-14 13:47:06 +02:00
|
|
|
## We need to escape the result. We unescape 'r' first in case 'r' to
|
|
|
|
## prevent double escaping.
|
2016-10-18 09:11:10 +02:00
|
|
|
switch (string sub -s 1 -l 1 -- (commandline -t))
|
2016-10-14 18:14:14 +02:00
|
|
|
case "'"
|
2016-10-18 09:11:10 +02:00
|
|
|
commandline -t -- (string escape -- (eval "printf '%s' '$r'"))
|
2016-10-14 18:14:14 +02:00
|
|
|
case '"'
|
|
|
|
set -l quoted (string escape -- (eval "printf '%s' '$r'"))
|
|
|
|
set -l len (string length $quoted)
|
2016-10-18 09:11:10 +02:00
|
|
|
commandline -t -- '"'(string sub -s 2 -l (math $len - 2) (string escape -- (eval "printf '%s' '$r'")))'"'
|
2016-10-14 18:14:14 +02:00
|
|
|
case '~'
|
2016-10-18 09:11:10 +02:00
|
|
|
commandline -t -- (string sub -s 2 (string escape -n -- (eval "printf '%s' '$r'")))
|
2016-10-14 13:47:06 +02:00
|
|
|
case '*'
|
2016-10-18 09:11:10 +02:00
|
|
|
commandline -t -- (string escape -n -- (eval "printf '%s' '$r'"))
|
2016-10-14 13:47:06 +02:00
|
|
|
end
|
2016-10-14 15:20:10 +02:00
|
|
|
[ $i -lt (count $result) ]; and commandline -i ' '
|
2016-10-14 12:37:43 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
commandline -f repaint
|
|
|
|
end
|
|
|
|
bind \t __fzf-complete
|
2016-11-27 05:01:20 +01:00
|
|
|
## TODO: 'complete' is not completely finished, keep original version for now.
|
|
|
|
bind \e\t complete
|
2016-10-14 12:37:43 +02:00
|
|
|
|
2016-10-13 11:09:04 +02:00
|
|
|
## DONE: Report missing (commandline) upstream.
|
|
|
|
## TODO: Report use of 'read'.
|
2016-11-27 05:01:20 +01:00
|
|
|
function __fzf-history-widget
|
|
|
|
history | eval (__fzfcmd) +m --tiebreak=index $FZF_CTRL_R_OPTS -q '(commandline)' | read -l result
|
2016-10-13 11:09:04 +02:00
|
|
|
and commandline -- $result
|
|
|
|
commandline -f repaint
|
|
|
|
end
|
2016-11-27 05:01:20 +01:00
|
|
|
bind \cr __fzf-history-widget
|
2016-10-13 11:09:04 +02:00
|
|
|
|
|
|
|
## Like original but uses last token as root for 'find'.
|
|
|
|
## If last token is a path, you can use it as $cwd in FZF_CTRL_T_COMMAND to
|
2016-10-19 08:14:48 +02:00
|
|
|
## restrict search to this path.
|
2016-10-13 11:09:04 +02:00
|
|
|
## TODO: Report upstream. Makes '**' obsolete for bash and zsh.
|
2016-11-27 05:01:20 +01:00
|
|
|
function __fzf-file-widget
|
2016-11-29 12:45:09 +01:00
|
|
|
set -l cwd (commandline -t)
|
2016-10-13 11:09:04 +02:00
|
|
|
## The commandline token might be escaped, we need to unescape it.
|
2016-11-29 12:45:09 +01:00
|
|
|
set cwd (eval "printf '%s' $cwd")
|
2016-10-14 12:38:22 +02:00
|
|
|
if [ ! -d "$cwd" ]
|
2016-10-13 11:09:04 +02:00
|
|
|
set cwd .
|
|
|
|
end
|
|
|
|
|
2016-10-14 18:14:14 +02:00
|
|
|
set -q FZF_CTRL_T_COMMAND; or set -l FZF_CTRL_T_COMMAND "
|
2016-11-29 12:45:09 +01:00
|
|
|
command find -L \$cwd \\( -path \$cwd'*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
|
2016-10-14 18:14:14 +02:00
|
|
|
-o -type f -print \
|
|
|
|
-o -type d -print \
|
|
|
|
-o -type l -print 2> /dev/null | sed 1d"
|
2016-10-13 11:09:04 +02:00
|
|
|
|
2016-10-16 14:04:03 +02:00
|
|
|
eval "$FZF_CTRL_T_COMMAND | "(__fzfcmd)" -m $FZF_CTRL_T_OPTS" | while read -l r; set result $result $r; end
|
2016-10-19 08:14:48 +02:00
|
|
|
if [ -z "$result" ]
|
|
|
|
commandline -f repaint
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if [ "$cwd" != . ]
|
|
|
|
## Remove last token from commandline.
|
|
|
|
commandline -t ""
|
|
|
|
end
|
|
|
|
for i in $result
|
2016-11-27 05:01:20 +01:00
|
|
|
commandline -it -- (string escape $i)
|
2016-10-19 08:14:48 +02:00
|
|
|
commandline -it -- ' '
|
2016-10-13 11:09:04 +02:00
|
|
|
end
|
2016-10-14 13:47:06 +02:00
|
|
|
commandline -f repaint
|
2016-10-13 11:09:04 +02:00
|
|
|
end
|
|
|
|
|
2016-11-27 05:01:20 +01:00
|
|
|
function __fzf-cd-widget
|
|
|
|
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-"
|
|
|
|
eval "$FZF_ALT_C_COMMAND | "(__fzfcmd)" +m --select-1 --exit-0 $FZF_ALT_C_OPTS" | read -l result
|
|
|
|
|
|
|
|
[ "$result" ]; and cd $result
|
|
|
|
commandline -f repaint
|
|
|
|
end
|
|
|
|
|
|
|
|
function __fzf-bcd-widget -d 'cd backwards'
|
|
|
|
## TODO: (fish upsteam bug) Cannot use eval here.
|
|
|
|
# pwd | awk -v RS=/ '/\n/ {exit} {p=p $0 "/"; print p}' | tac | eval (__fzfcmd) +m --select-1 --exit-0 $FZF_BCD_OPTS | read -l result
|
|
|
|
pwd | awk -v RS=/ '/\n/ {exit} {p=p $0 "/"; print p}' | tac | fzf +m --select-1 --exit-0 --preview='preview {}' | read -l result
|
2016-10-14 12:38:22 +02:00
|
|
|
[ "$result" ]; and cd $result
|
2016-10-13 11:09:04 +02:00
|
|
|
commandline -f repaint
|
|
|
|
end
|
2016-11-27 05:01:20 +01:00
|
|
|
bind \e\cL __fzf-bcd-widget
|
2016-10-13 11:09:04 +02:00
|
|
|
|
2016-11-27 05:01:20 +01:00
|
|
|
function __fzf-cdhist-widget -d 'cd to one of the previously visited location'
|
2016-11-27 13:27:47 +01:00
|
|
|
## Clear non-existent folders from cdhist.
|
|
|
|
set -l buf
|
|
|
|
for i in (seq 1 (count $dirprev))
|
|
|
|
set -l dir $dirprev[$i]
|
|
|
|
if test -d $dir
|
|
|
|
set buf $buf $dir
|
|
|
|
end
|
|
|
|
end
|
|
|
|
set dirprev $buf
|
2016-11-27 05:01:20 +01:00
|
|
|
## TODO: (fish upsteam bug) Cannot use eval here.
|
|
|
|
# string join \n $dirprev | tac | sed 1d | eval (__fzfcmd) +m $FZF_CDHIST_OPTS | read -l result
|
|
|
|
string join \n $dirprev | tac | sed 1d | fzf +m --preview='preview {}' | read -l result
|
2016-10-14 12:38:22 +02:00
|
|
|
[ "$result" ]; and cd $result
|
2016-10-13 11:09:04 +02:00
|
|
|
commandline -f repaint
|
|
|
|
end
|
2016-11-27 05:01:20 +01:00
|
|
|
bind \er __fzf-cdhist-widget
|