fish: Simplify fzf code
parent
ea6b3cc136
commit
7eaec4d8cd
|
@ -7,7 +7,7 @@ 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 | string join ' ' | read -l result
|
eval $cmd | eval (__fzfcmd) -m --tac --tiebreak=index --toggle-sort=ctrl-r --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,19 +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
|
||||||
switch (count $complist)
|
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
|
||||||
case 0
|
|
||||||
return
|
|
||||||
case 1
|
|
||||||
set result (printf '%s' "$complist[1]" | cut -f1)
|
|
||||||
case '*'
|
|
||||||
string join -- \n $complist | sort | eval (__fzfcmd) -m --tac --tiebreak=index --toggle-sort=ctrl-r | cut -f1 | while read -l r; set result $result $r; end
|
|
||||||
end
|
|
||||||
|
|
||||||
if [ -z "$result" ]
|
|
||||||
commandline -f repaint
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
for i in (seq (count $result))
|
for i in (seq (count $result))
|
||||||
set -l r $result[$i]
|
set -l r $result[$i]
|
||||||
|
@ -63,8 +51,7 @@ end
|
||||||
|
|
||||||
## 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. $cwd will be suppressed from commandline to
|
## restrict search to this path.
|
||||||
## ensure clean output from the search results.
|
|
||||||
## 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)
|
||||||
|
@ -81,21 +68,24 @@ function fzf-file-widget
|
||||||
-o -type l -print 2> /dev/null | sed 1d"
|
-o -type l -print 2> /dev/null | sed 1d"
|
||||||
|
|
||||||
eval "$FZF_CTRL_T_COMMAND | "(__fzfcmd)" -m $FZF_CTRL_T_OPTS" | while read -l r; set result $result $r; end
|
eval "$FZF_CTRL_T_COMMAND | "(__fzfcmd)" -m $FZF_CTRL_T_OPTS" | while read -l r; set result $result $r; end
|
||||||
if [ -n "$result" ]
|
if [ -z "$result" ]
|
||||||
if [ "$cwd" != . ]
|
commandline -f repaint
|
||||||
## Remove last token from commandline.
|
return
|
||||||
commandline -t ""
|
end
|
||||||
end
|
|
||||||
for i in $result
|
if [ "$cwd" != . ]
|
||||||
commandline -it -- (string escape (eval "printf '%s' '$i'"))
|
## Remove last token from commandline.
|
||||||
commandline -it -- ' '
|
commandline -t ""
|
||||||
end
|
end
|
||||||
|
for i in $result
|
||||||
|
commandline -it -- (string escape (eval "printf '%s' '$i'"))
|
||||||
|
commandline -it -- ' '
|
||||||
end
|
end
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
end
|
end
|
||||||
|
|
||||||
function fzf-bcd-widget -d 'cd backwards'
|
function fzf-bcd-widget -d 'cd backwards'
|
||||||
pwd | nawk -v RS=/ '/\n/ {exit} {p=p $0 "/"; print p}' | eval (__fzfcmd) +m --tac | read -l result
|
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
|
[ "$result" ]; and cd $result
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue