2006-07-10 07:55:18 +08:00
|
|
|
function __fish_complete_cd -d "Completions for the cd command"
|
2015-08-10 22:15:45 +08:00
|
|
|
set -l cdpath $CDPATH
|
|
|
|
[ -z "$cdpath" ]; and set cdpath "."
|
|
|
|
# Remove the real path to "." (i.e. $PWD) from cdpath if we're in it
|
|
|
|
# so it doesn't get printed in the descriptions
|
|
|
|
set -l ind
|
|
|
|
if begin; set ind (contains -i -- $PWD $cdpath)
|
|
|
|
and contains -- "." $cdpath
|
|
|
|
end
|
|
|
|
set -e cdpath[$ind]
|
|
|
|
end
|
|
|
|
for i in $cdpath
|
|
|
|
set -l desc
|
|
|
|
# Don't show description for current directory
|
|
|
|
# and replace $HOME with "~"
|
|
|
|
[ $i = "." ]; or set -l desc (string replace -r -- "^$HOME" "~" "$i")
|
|
|
|
pushd $i
|
|
|
|
for d in (commandline -ct)*/
|
|
|
|
# Check if it's accessible - the glob only matches directories
|
2015-10-08 04:39:42 +08:00
|
|
|
[ -x $d ]; and printf "%s\t%s\n" $d $desc
|
2006-07-10 07:55:18 +08:00
|
|
|
end
|
2015-08-10 22:15:45 +08:00
|
|
|
popd
|
2006-07-10 07:55:18 +08:00
|
|
|
end
|
|
|
|
end
|