diff --git a/share/completions/cd.fish b/share/completions/cd.fish index 93eadcb75..ff34cee4c 100644 --- a/share/completions/cd.fish +++ b/share/completions/cd.fish @@ -1,39 +1,2 @@ -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)" diff --git a/share/functions/__fish_complete_cd.fish b/share/functions/__fish_complete_cd.fish new file mode 100644 index 000000000..f498f2a13 --- /dev/null +++ b/share/functions/__fish_complete_cd.fish @@ -0,0 +1,43 @@ +function __fish_complete_cd -d "Completions for the cd command" + + # + # We can't simply use __fish_complete_directory because of the CDPATH + # + + 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 + + + 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 +