scripts/cd in rvm-1.0.19 vs scripts/cd in rvm-1.0.20

- old
+ new

@@ -43,49 +43,29 @@ rvm_hook="after_cd" ; source "$rvm_path/scripts/hook" return $result } - # - # Can someone please explain to me what this was meant to accomplish? - # telemachus was encountering issues when he had CDPATH set. - # Namely comletion stopped working. - # - # _rvm_cd_complete () - # { - # local directory current matches item index - - # COMPREPLY=() - - # current="${COMP_WORDS[COMP_CWORD]}" - - # if [[ -n "$CDPATH" ]] ; then - - # index=${#COMPREPLY[@]} - - # for directory in $(printf "$CDPATH" | tr -s ':' ' ') ; do - - # for item in $( compgen -d "$directory/$current" ) ; do - - # item="${item}/" - - # COMPREPLY[index++]=${item#$directory/} - - # done - - # done - - # COMPREPLY=( $(echo ${COMPREPLY} | uniq | sort) ) - - # else - - # COMPREPLY=( $(compgen -d ${current}) ) - - # fi - - # } - - # complete -o filenames -o dirnames -o nospace -F _rvm_cd_complete cd + # If $CDPATH is set, bash should tab-complete based on directories in those paths, + # but with the cd function above, the built-in tab-complete ignores $CDPATH. This + # function returns that functionality. + _rvm_cd_complete () + { + local directory current matches item index + COMPREPLY=() + current="${COMP_WORDS[COMP_CWORD]}" + if [[ -n "$CDPATH" && ${current:0:1} != "/" ]] ; then + index=0 + for directory in $(printf "$CDPATH" | tr -s ':' ' ') ; do + for item in $( compgen -d "$directory/$current" ) ; do + COMPREPLY[index++]=${item#$directory/} + done + done + else + COMPREPLY=( $(compgen -d ${current}) ) + fi + } + complete -o bashdefault -o default -o filenames -o dirnames -o nospace -F _rvm_cd_complete cd fi fi