fzf: Use preview, reverse, inline, fix some issues

master
Pierre Neidhardt 2016-11-27 09:31:20 +05:30
parent 2a568ba675
commit 5ece42f9cf
2 changed files with 39 additions and 18 deletions

View File

@ -1,13 +1,13 @@
fzf_key_bindings
bind \cT transpose-chars
bind \e\ct fzf-file-widget
bind \e\ct __fzf-file-widget
bind \ec capitalize-word
bind \eC fzf-cd-widget
bind \eC __fzf-cd-widget
function __fzf-select -d 'fzf commandline and print unescaped selection back to commandline'
set -l cmd (commandline -j)
[ "$cmd" ]; or return
eval $cmd | eval (__fzfcmd) -m --tac --tiebreak=index --toggle-sort=ctrl-r --select-1 --exit-0 | string join ' ' | read -l result
eval $cmd | eval (__fzfcmd) -m --tiebreak=index --select-1 --exit-0 | string join ' ' | read -l result
[ "$result" ]; and commandline -j -- $result
commandline -f repaint
end
@ -16,7 +16,7 @@ bind \e\cm __fzf-select
function __fzf-complete -d 'fzf completion and print selection back to commandline'
set -l complist (complete -C(commandline -c))
set -l result
string join -- \n $complist | sort | eval (__fzfcmd) -m --tac --tiebreak=index --toggle-sort=ctrl-r --select-1 --exit-0 | cut -f1 | while read -l r; set result $result $r; end
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
for i in (seq (count $result))
set -l r $result[$i]
@ -40,20 +40,23 @@ function __fzf-complete -d 'fzf completion and print selection back to commandli
commandline -f repaint
end
bind \t __fzf-complete
## TODO: 'complete' is not completely finished, keep original version for now.
bind \e\t complete
## DONE: Report missing (commandline) upstream.
## TODO: Report use of 'read'.
function fzf-history-widget
history | eval (__fzfcmd) +m --tiebreak=index --toggle-sort=ctrl-r $FZF_CTRL_R_OPTS -q '(commandline)' | read -l result
function __fzf-history-widget
history | eval (__fzfcmd) +m --tiebreak=index $FZF_CTRL_R_OPTS -q '(commandline)' | read -l result
and commandline -- $result
commandline -f repaint
end
bind \cr __fzf-history-widget
## 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
## restrict search to this path.
## TODO: Report upstream. Makes '**' obsolete for bash and zsh.
function fzf-file-widget
function __fzf-file-widget
set -l cwd_esc (commandline -t)
## The commandline token might be escaped, we need to unescape it.
set -l cwd (eval "printf '%s' $cwd_esc")
@ -78,22 +81,36 @@ function fzf-file-widget
commandline -t ""
end
for i in $result
commandline -it -- (string escape (eval "printf '%s' '$i'"))
commandline -it -- (string escape $i)
commandline -it -- ' '
end
commandline -f repaint
end
function fzf-bcd-widget -d 'cd backwards'
pwd | nawk -v RS=/ '/\n/ {exit} {p=p $0 "/"; print p}' | eval (__fzfcmd) +m --tac --select-1 --exit-0 | read -l result
[ "$result" ]; and cd $result
commandline -f repaint
end
bind \e\cL fzf-bcd-widget
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
function fzf-cdhist-widget -d 'cd to one of the previously visited location'
string join \n $dirprev | eval (__fzfcmd) +m --tac | 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
[ "$result" ]; and cd $result
commandline -f repaint
end
bind \er fzf-cdhist-widget
bind \e\cL __fzf-bcd-widget
function __fzf-cdhist-widget -d 'cd to one of the previously visited location'
## 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
[ "$result" ]; and cd $result
commandline -f repaint
end
bind \er __fzf-cdhist-widget

View File

@ -130,7 +130,11 @@ fi
## fzf
if command -v fzf >/dev/null 2>&1; then
export FZF_DEFAULT_OPTS="--cycle --extended --multi --bind=ctrl-v:page-down,alt-v:page-up,alt-a:toggle-all"
export FZF_DEFAULT_OPTS="--reverse --inline-info --cycle --extended --multi --bind=ctrl-k:kill-line,ctrl-j:accept,alt-s:toggle-sort,ctrl-v:page-down,alt-v:page-up,alt-a:toggle-all,alt-i:toggle-up,alt-z:toggle-preview"
export FZF_ALT_C_OPTS="--preview='preview {}'"
export FZF_BCD_OPTS=$FZF_ALT_C_OPTS
export FZF_CDHIST_OPTS=$FZF_ALT_C_OPTS
export FZF_CTRL_T_OPTS="--bind=ctrl-j:'execute-multi(rifle {})' --preview='preview {}'"
fi
## pacman abs