fzf: Use preview, reverse, inline, fix some issues
parent
2a568ba675
commit
5ece42f9cf
|
@ -1,13 +1,13 @@
|
||||||
fzf_key_bindings
|
fzf_key_bindings
|
||||||
bind \cT transpose-chars
|
bind \cT transpose-chars
|
||||||
bind \e\ct fzf-file-widget
|
bind \e\ct __fzf-file-widget
|
||||||
bind \ec capitalize-word
|
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'
|
function __fzf-select -d 'fzf commandline and print unescaped selection back to commandline'
|
||||||
set -l cmd (commandline -j)
|
set -l cmd (commandline -j)
|
||||||
[ "$cmd" ]; or return
|
[ "$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
|
[ "$result" ]; and commandline -j -- $result
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
end
|
end
|
||||||
|
@ -16,7 +16,7 @@ bind \e\cm __fzf-select
|
||||||
function __fzf-complete -d 'fzf completion and print selection back to commandline'
|
function __fzf-complete -d 'fzf completion and print selection back to commandline'
|
||||||
set -l complist (complete -C(commandline -c))
|
set -l complist (complete -C(commandline -c))
|
||||||
set -l result
|
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))
|
for i in (seq (count $result))
|
||||||
set -l r $result[$i]
|
set -l r $result[$i]
|
||||||
|
@ -40,20 +40,23 @@ function __fzf-complete -d 'fzf completion and print selection back to commandli
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
end
|
end
|
||||||
bind \t __fzf-complete
|
bind \t __fzf-complete
|
||||||
|
## TODO: 'complete' is not completely finished, keep original version for now.
|
||||||
|
bind \e\t complete
|
||||||
|
|
||||||
## DONE: Report missing (commandline) upstream.
|
## DONE: Report missing (commandline) upstream.
|
||||||
## TODO: Report use of 'read'.
|
## TODO: Report use of 'read'.
|
||||||
function fzf-history-widget
|
function __fzf-history-widget
|
||||||
history | eval (__fzfcmd) +m --tiebreak=index --toggle-sort=ctrl-r $FZF_CTRL_R_OPTS -q '(commandline)' | read -l result
|
history | eval (__fzfcmd) +m --tiebreak=index $FZF_CTRL_R_OPTS -q '(commandline)' | read -l result
|
||||||
and commandline -- $result
|
and commandline -- $result
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
end
|
end
|
||||||
|
bind \cr __fzf-history-widget
|
||||||
|
|
||||||
## Like original but uses last token as root for 'find'.
|
## 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
|
## If last token is a path, you can use it as $cwd in FZF_CTRL_T_COMMAND to
|
||||||
## restrict search to this path.
|
## restrict search to this path.
|
||||||
## TODO: Report upstream. Makes '**' obsolete for bash and zsh.
|
## TODO: Report upstream. Makes '**' obsolete for bash and zsh.
|
||||||
function fzf-file-widget
|
function __fzf-file-widget
|
||||||
set -l cwd_esc (commandline -t)
|
set -l cwd_esc (commandline -t)
|
||||||
## The commandline token might be escaped, we need to unescape it.
|
## The commandline token might be escaped, we need to unescape it.
|
||||||
set -l cwd (eval "printf '%s' $cwd_esc")
|
set -l cwd (eval "printf '%s' $cwd_esc")
|
||||||
|
@ -78,22 +81,36 @@ function fzf-file-widget
|
||||||
commandline -t ""
|
commandline -t ""
|
||||||
end
|
end
|
||||||
for i in $result
|
for i in $result
|
||||||
commandline -it -- (string escape (eval "printf '%s' '$i'"))
|
commandline -it -- (string escape $i)
|
||||||
commandline -it -- ' '
|
commandline -it -- ' '
|
||||||
end
|
end
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
end
|
end
|
||||||
|
|
||||||
function fzf-bcd-widget -d 'cd backwards'
|
function __fzf-cd-widget
|
||||||
pwd | nawk -v RS=/ '/\n/ {exit} {p=p $0 "/"; print p}' | eval (__fzfcmd) +m --tac --select-1 --exit-0 | read -l result
|
set -q FZF_ALT_C_COMMAND; or set -l FZF_ALT_C_COMMAND "
|
||||||
[ "$result" ]; and cd $result
|
command find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
|
||||||
commandline -f repaint
|
-o -type d -print 2> /dev/null | sed 1d | cut -b3-"
|
||||||
end
|
eval "$FZF_ALT_C_COMMAND | "(__fzfcmd)" +m --select-1 --exit-0 $FZF_ALT_C_OPTS" | read -l result
|
||||||
bind \e\cL fzf-bcd-widget
|
|
||||||
|
|
||||||
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
|
[ "$result" ]; and cd $result
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
end
|
end
|
||||||
bind \er fzf-cdhist-widget
|
|
||||||
|
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 \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
|
||||||
|
|
6
.profile
6
.profile
|
@ -130,7 +130,11 @@ fi
|
||||||
|
|
||||||
## fzf
|
## fzf
|
||||||
if command -v fzf >/dev/null 2>&1; then
|
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
|
fi
|
||||||
|
|
||||||
## pacman abs
|
## pacman abs
|
||||||
|
|
Loading…
Reference in New Issue