scripts/cd in rvm-1.0.11 vs scripts/cd in rvm-1.0.13

- old
+ new

@@ -7,17 +7,22 @@ if [[ -n "${ZSH_VERSION:-""}" ]] ; then autoload is-at-least if is-at-least 4.3.4 >/dev/null 2>&1; then + # On zsh, use chpwd_functions chpwd_functions=( "${chpwd_functions[@]}" __rvm_project_rvmrc ) + else - cd() { + cd() + { builtin cd "$@" + local result=$? + __rvm_project_rvmrc rvm_hook="after_cd" ; source "$rvm_path/scripts/hook" return $result @@ -25,33 +30,57 @@ fi else - cd() { + cd() + { builtin cd "$@" + local result=$? + __rvm_project_rvmrc rvm_hook="after_cd" ; source "$rvm_path/scripts/hook" return $result } _rvm_cd_complete () { - local cur matches + local directory current matches item index + COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - matches=$(for dir in $(echo $CDPATH | tr -s ':' ' ') ; do - find $dir/* -type d -maxdepth 0 -exec basename {} \; - done | sort | uniq) + current="${COMP_WORDS[COMP_CWORD]}" - COMPREPLY=( $(compgen -W "${matches}" -- ${cur}) ) - } + if [[ -n "$CDPATH" ]] ; then - complete -o bashdefault -o default -o dirnames -o filenames -o nospace -o plusdirs -F _rvm_cd_complete cd + index=${#COMPREPLY[@]} + + for directory in $(echo "$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 nospace -F _rvm_cd_complete cd + + } fi fi