2017-06-02 00:49:01 +00:00
|
|
|
# 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.
|
2006-07-09 23:55:18 +00:00
|
|
|
function __fish_complete_cd -d "Completions for the cd command"
|
2017-06-02 00:49:01 +00:00
|
|
|
set -q CDPATH[1]
|
|
|
|
or return 0 # no CDPATH so rely solely on the core file name completions
|
|
|
|
|
2016-11-28 05:27:22 +00:00
|
|
|
set -l token (commandline -ct)
|
2017-06-02 00:49:01 +00:00
|
|
|
if string match -qr '^\.{0,2}/.*' -- $token
|
|
|
|
# Absolute path or explicitly relative to the current directory. Rely on the builtin file
|
|
|
|
# name completions since we no longer exclude them from the `cd` argument completion.
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
# Relative path. Check $CDPATH and use that as the description for any possible matches.
|
|
|
|
# We deliberately exclude the `.` path because the core file name completion logic will include
|
|
|
|
# it when presenting possible matches.
|
|
|
|
set -l cdpath (string match -v '.' -- $CDPATH)
|
|
|
|
|
|
|
|
# Remove the CWD if it is in CDPATH since, again, the core file name completion logic will
|
|
|
|
# handle it.
|
|
|
|
set -l cdpath (string match -v -- $PWD $cdpath)
|
|
|
|
set -q cdpath[1]
|
|
|
|
or return 0
|
|
|
|
|
|
|
|
# TODO: There's a subtlety regarding descriptions - if $cdpath[1]/foo and $cdpath[2]/foo
|
|
|
|
# exist, we print both but want the first description to win - this currently works, but
|
|
|
|
# is not guaranteed.
|
|
|
|
for cdpath in $cdpath
|
|
|
|
# Replace $HOME with "~".
|
|
|
|
set -l desc (string replace -r -- "^$HOME" "~" "$cdpath")
|
|
|
|
# This assumes the CDPATH component itself is cd-able.
|
|
|
|
for d in $cdpath/$token*/
|
|
|
|
# Remove the cdpath component again.
|
|
|
|
test -x $d
|
|
|
|
and printf "%s\tCDPATH %s\n" (string replace -r "^$cdpath/" "" -- $d) $desc
|
2016-11-28 05:27:22 +00:00
|
|
|
end
|
|
|
|
end
|
2006-07-09 23:55:18 +00:00
|
|
|
end
|