mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-14 17:07:44 +00:00
7ddecde543
darcs-hash:20050920133155-ac50b-9a14c6c664dd03afbe8e15e7c7998fcfb5c3c750.gz
39 lines
862 B
Fish
39 lines
862 B
Fish
|
|
function __fish_complete_cd -d "Completions for the cd command"
|
|
|
|
#
|
|
# We can't simply use __fish_complete_directory because of the CDPATH
|
|
#
|
|
|
|
set -- wd $PWD
|
|
set -- owd $OLDPWD
|
|
|
|
# Check if CDPATH is set
|
|
|
|
set -l mycdpath
|
|
|
|
if test -z $CDPATH[1]
|
|
set mycdpath .
|
|
else
|
|
set mycdpath $CDPATH
|
|
end
|
|
|
|
if echo (commandline -ct)|grep '^/' >/dev/null
|
|
# 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
|
|
|
|
complete -x -c cd -a "(__fish_complete_cd)"
|