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-11-18 18:23:22 +08:00
|
|
|
|
2012-08-16 09:20:44 +08:00
|
|
|
# Note how this works: we evaluate $ctoken*/
|
|
|
|
# That trailing slash ensures that we only expand directories
|
2006-07-10 07:55:18 +08:00
|
|
|
|
2013-02-21 10:43:54 +08:00
|
|
|
set -l ctoken (commandline -ct)
|
2012-06-26 08:01:35 +08:00
|
|
|
if echo $ctoken | sgrep '^/\|^\./\|^\.\./\|^~/' >/dev/null
|
2006-07-10 07:55:18 +08:00
|
|
|
# This is an absolute search path
|
2012-08-16 09:20:44 +08:00
|
|
|
# Squelch descriptions per issue 254
|
|
|
|
eval printf '\%s\\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
|
2013-11-26 16:07:18 +08:00
|
|
|
builtin cd $wd ^/dev/null
|
|
|
|
builtin cd $i ^/dev/null
|
|
|
|
|
|
|
|
if test $status -ne 0
|
|
|
|
# directory does not exists or missing permission
|
|
|
|
continue
|
|
|
|
end
|
2006-07-10 07:55:18 +08:00
|
|
|
|
2012-08-16 09:20:44 +08:00
|
|
|
# What we would really like to do is skip descriptions if all
|
|
|
|
# valid paths are in the same directory, but we don't know how to
|
|
|
|
# do that yet; so instead skip descriptions if CDPATH is just .
|
|
|
|
if test "$mycdpath" = .
|
|
|
|
eval printf '"%s\n"' $ctoken\*/
|
|
|
|
else
|
|
|
|
eval printf '"%s\tin "'$i'"\n"' $ctoken\*/
|
|
|
|
end
|
2006-07-10 07:55:18 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-26 16:07:18 +08:00
|
|
|
builtin cd $wd ^/dev/null
|
2006-07-10 07:55:18 +08:00
|
|
|
end
|