fish: Fix tests on variables in fzf code
parent
03f58e8275
commit
63aca3978a
|
@ -4,6 +4,7 @@ bind \e\ct fzf-file-widget
|
||||||
bind \ec capitalize-word
|
bind \ec capitalize-word
|
||||||
bind \eC fzf-cd-widget
|
bind \eC fzf-cd-widget
|
||||||
|
|
||||||
|
## TODO: Force --no-cycle or use global?
|
||||||
function __fzf-select -d 'fzf commandline and print selection back to commandline. Awesome!'
|
function __fzf-select -d 'fzf commandline and print selection back to commandline. Awesome!'
|
||||||
set -l cmd (commandline)
|
set -l cmd (commandline)
|
||||||
[ $cmd ]; or return
|
[ $cmd ]; or return
|
||||||
|
@ -60,11 +61,12 @@ end
|
||||||
## restrict search to this path. $cwd will be suppressed from commandline to
|
## restrict search to this path. $cwd will be suppressed from commandline to
|
||||||
## ensure clean output from the search results.
|
## 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.
|
||||||
|
## TODO: Do not use temp file.
|
||||||
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 "echo $cwd_esc")
|
set -l cwd (eval "echo $cwd_esc")
|
||||||
if [ ! -d $cwd ]
|
if [ ! -d "$cwd" ]
|
||||||
set cwd .
|
set cwd .
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -75,13 +77,13 @@ function fzf-file-widget
|
||||||
-o -type l -print 2> /dev/null | sed 1d"
|
-o -type l -print 2> /dev/null | sed 1d"
|
||||||
|
|
||||||
if eval $FZF_CTRL_T_COMMAND | eval (__fzfcmd) -m $FZF_CTRL_T_OPTS > $TMPDIR/fzf.result
|
if eval $FZF_CTRL_T_COMMAND | eval (__fzfcmd) -m $FZF_CTRL_T_OPTS > $TMPDIR/fzf.result
|
||||||
if [ $cwd != . ]
|
if [ "$cwd" != . ]
|
||||||
## Remove path from commandline: it will be
|
## Remove last token from commandline.
|
||||||
set -l cmd (commandline)
|
set -l cmd (commandline)
|
||||||
set -l len (math (string length $cmd) - (string length $cwd_esc))
|
set -l len (math (string length $cmd) - (string length $cwd_esc))
|
||||||
commandline -- (string sub -l $len (commandline))
|
commandline -- (string sub -l $len (commandline))
|
||||||
end
|
end
|
||||||
for i in (seq 20); commandline -i (cat $TMPDIR/fzf.result | __fzf_escape) 2> /dev/null; and break; sleep 0.1; end
|
for i in (seq 20); commandline -i (cat $TMPDIR/fzf.result | __fzf_escape) ^ /dev/null; and break; sleep 0.1; end
|
||||||
end
|
end
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
rm -f $TMPDIR/fzf.result
|
rm -f $TMPDIR/fzf.result
|
||||||
|
@ -89,14 +91,14 @@ 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 | read -l result
|
||||||
[ $result ]; and cd $result
|
[ "$result" ]; and cd $result
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
end
|
end
|
||||||
bind \e\cL fzf-bcd-widget
|
bind \e\cL fzf-bcd-widget
|
||||||
|
|
||||||
function fzf-cdhist-widget -d 'cd to one of the previously visited location'
|
function fzf-cdhist-widget -d 'cd to one of the previously visited location'
|
||||||
string join \n $dirprev | eval (__fzfcmd) +m | read -l result
|
string join \n $dirprev | eval (__fzfcmd) +m | read -l result
|
||||||
[ $result ]; and cd $result
|
[ "$result" ]; and cd $result
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
end
|
end
|
||||||
bind \er fzf-cdhist-widget
|
bind \er fzf-cdhist-widget
|
||||||
|
|
Loading…
Reference in New Issue