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
|
|
|
|
set -l owd $OLDPWD
|
|
|
|
|
|
|
|
# Check if CDPATH is set
|
|
|
|
|
|
|
|
set -l mycdpath
|
|
|
|
|
|
|
|
if test -z $CDPATH[1]
|
|
|
|
set mycdpath .
|
|
|
|
else
|
|
|
|
set mycdpath $CDPATH
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2006-11-29 22:00:04 +08:00
|
|
|
if echo (commandline -ct)|sgrep '^/\|^\./\|^\.\./' >/dev/null
|
2006-07-10 07:55:18 +08:00
|
|
|
# This is an absolute search path
|
|
|
|
eval printf '\%s\\tDirectory\\n' (commandline -ct)\*/
|
|
|
|
else
|
|
|
|
# This is a relative search path
|
|
|
|
# Iterate over every directory in CDPATH
|
|
|
|
# and check for possible completions
|
|
|
|
|
|
|
|
for i in $mycdpath
|
|
|
|
# Move to the initial directory first,
|
|
|
|
# in case the CDPATH directory is relative
|
|
|
|
|
|
|
|
builtin cd $wd
|
|
|
|
builtin cd $i
|
|
|
|
|
|
|
|
eval printf '"%s\tDirectory in "'$i'"\n"' (commandline -ct)\*/
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
builtin cd $wd
|
|
|
|
set OLDPWD $owd
|
|
|
|
end
|
|
|
|
|