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'
|
||||
set -l cmd (commandline -j)
|
||||
[ "$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
|
||||
commandline -f repaint
|
||||
end
|
||||
|
@ -16,19 +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
|
||||
switch (count $complist)
|
||||
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
|
||||
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
|
||||
|
||||
for i in (seq (count $result))
|
||||
set -l r $result[$i]
|
||||
|
@ -63,8 +51,7 @@ end
|
|||
|
||||
## 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. $cwd will be suppressed from commandline to
|
||||
## ensure clean output from the search results.
|
||||
## restrict search to this path.
|
||||
## TODO: Report upstream. Makes '**' obsolete for bash and zsh.
|
||||
function fzf-file-widget
|
||||
set -l cwd_esc (commandline -t)
|
||||
|
@ -81,21 +68,24 @@ function fzf-file-widget
|
|||
-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
|
||||
if [ -n "$result" ]
|
||||
if [ "$cwd" != . ]
|
||||
## Remove last token from commandline.
|
||||
commandline -t ""
|
||||
end
|
||||
for i in $result
|
||||
commandline -it -- (string escape (eval "printf '%s' '$i'"))
|
||||
commandline -it -- ' '
|
||||
end
|
||||
if [ -z "$result" ]
|
||||
commandline -f repaint
|
||||
return
|
||||
end
|
||||
|
||||
if [ "$cwd" != . ]
|
||||
## Remove last token from commandline.
|
||||
commandline -t ""
|
||||
end
|
||||
for i in $result
|
||||
commandline -it -- (string escape (eval "printf '%s' '$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 | 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
|
||||
commandline -f repaint
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue