2006-07-09 23:55:18 +00:00
|
|
|
function __fish_complete_cd -d "Completions for the cd command"
|
|
|
|
#
|
2006-12-02 23:34:33 +00:00
|
|
|
# We can't simply use __fish_complete_directories because of the CDPATH
|
2006-07-09 23:55:18 +00: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 10:23:22 +00:00
|
|
|
|
2012-08-16 01:20:44 +00:00
|
|
|
# Note how this works: we evaluate $ctoken*/
|
|
|
|
# That trailing slash ensures that we only expand directories
|
2006-07-09 23:55:18 +00:00
|
|
|
|
2013-02-21 02:43:54 +00:00
|
|
|
set -l ctoken (commandline -ct)
|
2012-06-26 00:01:35 +00:00
|
|
|
if echo $ctoken | sgrep '^/\|^\./\|^\.\./\|^~/' >/dev/null
|
2006-07-09 23:55:18 +00:00
|
|
|
# This is an absolute search path
|
2012-08-16 01:20:44 +00:00
|
|
|
# Squelch descriptions per issue 254
|
|
|
|
eval printf '\%s\\n' $ctoken\*/
|
2006-07-09 23:55:18 +00:00
|
|
|
else
|
|
|
|
# This is a relative search path
|
2010-09-18 02:18:26 +00:00
|
|
|
# Iterate over every directory in CDPATH
|
2006-07-09 23:55:18 +00:00
|
|
|
# and check for possible completions
|
|
|
|
|
|
|
|
for i in $mycdpath
|
2010-09-18 02:18:26 +00:00
|
|
|
# Move to the initial directory first,
|
2006-07-09 23:55:18 +00:00
|
|
|
# in case the CDPATH directory is relative
|
|
|
|
|
|
|
|
builtin cd $wd
|
2013-02-21 02:43:54 +00:00
|
|
|
builtin cd $i
|
2006-07-09 23:55:18 +00:00
|
|
|
|
2012-08-16 01:20:44 +00: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-09 23:55:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
builtin cd $wd
|
|
|
|
end
|