remove redundant output from __fish_complete_cd

Fixes #4085
This commit is contained in:
Kurtis Rader 2017-06-01 17:49:01 -07:00
parent ee646c8dd0
commit b8aacc29cd

View file

@ -1,36 +1,38 @@
# This function only emits completions that might result from matches against $CDPATH. We rely on
# the core file name completion logic to include all other possible matches.
function __fish_complete_cd -d "Completions for the cd command" function __fish_complete_cd -d "Completions for the cd command"
set -q CDPATH[1]
or return 0 # no CDPATH so rely solely on the core file name completions
set -l token (commandline -ct) set -l token (commandline -ct)
# Absolute path or explicitly from the current directory - no descriptions and no CDPATH if string match -qr '^\.{0,2}/.*' -- $token
if string match -qr '^\.?\.?/.*' -- $token # Absolute path or explicitly relative to the current directory. Rely on the builtin file
for d in $token*/ # name completions since we no longer exclude them from the `cd` argument completion.
# Check if it's accessible - the glob only matches directories return
[ -x $d ] end
and printf "%s\n" $d
end # Relative path. Check $CDPATH and use that as the description for any possible matches.
else # Relative path - check $CDPATH and use that as description # We deliberately exclude the `.` path because the core file name completion logic will include
set -l cdpath $CDPATH # it when presenting possible matches.
[ -z "$cdpath" ] set -l cdpath (string match -v '.' -- $CDPATH)
and set cdpath "."
# Remove the real path to "." (i.e. $PWD) from cdpath if we're in it # Remove the CWD if it is in CDPATH since, again, the core file name completion logic will
# so it doesn't get printed in the descriptions # handle it.
if set -l ind (contains -i -- $PWD $cdpath) set -l cdpath (string match -v -- $PWD $cdpath)
and contains -- "." $cdpath set -q cdpath[1]
set -e cdpath[$ind] or return 0
end
# TODO: There's a subtlety regarding descriptions - if $cdpath[1]/foo and $cdpath[2]/foo exist, we print both # TODO: There's a subtlety regarding descriptions - if $cdpath[1]/foo and $cdpath[2]/foo
# but want the first description to win - this currently works, but is not guaranteed # exist, we print both but want the first description to win - this currently works, but
for i in $cdpath # is not guaranteed.
set -l desc for cdpath in $cdpath
# Don't show description for current directory # Replace $HOME with "~".
# and replace $HOME with "~" set -l desc (string replace -r -- "^$HOME" "~" "$cdpath")
[ $i = "." ] # This assumes the CDPATH component itself is cd-able.
or set -l desc (string replace -r -- "^$HOME" "~" "$i") for d in $cdpath/$token*/
# This assumes the CDPATH component itself is cd-able # Remove the cdpath component again.
for d in $i/$token*/ test -x $d
# Remove the cdpath component again and printf "%s\tCDPATH %s\n" (string replace -r "^$cdpath/" "" -- $d) $desc
[ -x $d ]
and printf "%s\t%s\n" (string replace -r "^$i/" "" -- $d) $desc
end
end end
end end
end end