2006-07-10 07:55:18 +08:00
|
|
|
function __fish_complete_cd -d "Completions for the cd command"
|
|
|
|
#
|
2006-12-03 07:34:33 +08:00
|
|
|
# We can't simply use __fish_complete_directories because of the CDPATH
|
2006-07-10 07:55:18 +08:00
|
|
|
#
|
|
|
|
set -l wd $PWD
|
|
|
|
|
|
|
|
# Check if CDPATH is set
|
|
|
|
|
|
|
|
set -l mycdpath
|
|
|
|
|
|
|
|
if test -z $CDPATH[1]
|
|
|
|
set mycdpath .
|
|
|
|
else
|
|
|
|
set mycdpath $CDPATH
|
|
|
|
end
|
|
|
|
|
2012-06-26 08:01:35 +08:00
|
|
|
set -l ctoken (commandline -ct)
|
|
|
|
if echo $ctoken | sgrep '^/\|^\./\|^\.\./\|^~/' >/dev/null
|
2006-07-10 07:55:18 +08:00
|
|
|
# This is an absolute search path
|
2012-06-26 08:01:35 +08:00
|
|
|
eval printf '\%s\\tDirectory\\n' $ctoken\*/
|
2006-07-10 07:55:18 +08:00
|
|
|
else
|
|
|
|
# This is a relative search path
|
2010-09-18 10:18:26 +08:00
|
|
|
# Iterate over every directory in CDPATH
|
2006-07-10 07:55:18 +08:00
|
|
|
# and check for possible completions
|
|
|
|
|
|
|
|
for i in $mycdpath
|
2010-09-18 10:18:26 +08:00
|
|
|
# Move to the initial directory first,
|
2006-07-10 07:55:18 +08:00
|
|
|
# in case the CDPATH directory is relative
|
|
|
|
|
|
|
|
builtin cd $wd
|
2010-09-17 16:01:44 +08:00
|
|
|
eval builtin cd $i
|
2006-07-10 07:55:18 +08:00
|
|
|
|
2012-06-26 08:01:35 +08:00
|
|
|
eval printf '"%s\tDirectory in "'$i'"\n"' $ctoken\*/
|
2006-07-10 07:55:18 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
builtin cd $wd
|
|
|
|
end
|
|
|
|
|