#!/usr/bin/env bash # Source a .rvmrc file in a directory after changing to it, if it exists. # To disable this fature, set export rvm_project_rvmrc=0 in $HOME/.rvmrc if [[ ${rvm_project_rvmrc:-1} -ne 0 ]] ; then 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() { builtin cd "$@" local result=$? __rvm_project_rvmrc rvm_hook="after_cd" ; source "$rvm_path/scripts/hook" return $result } fi else cd() { builtin cd "$@" local result=$? __rvm_project_rvmrc rvm_hook="after_cd" ; source "$rvm_path/scripts/hook" return $result } # 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 sep sep="${IFS}" declare -x IFS=$'\n' COMPREPLY=() current="${COMP_WORDS[COMP_CWORD]}" if [[ -n "$CDPATH" && ${current:0:1} != "/" ]] ; then index=0 for directory in $(printf "%s" "$CDPATH" | tr -s ':' ' ') ; do for item in $( compgen -d "$directory/$current" ) ; do COMPREPLY[index++]=${item#$directory/} done done else COMPREPLY=( $(compgen -d ${current}) ) fi declare -x IFS="${sep}"; } complete -o bashdefault -o default -o filenames -o dirnames -o nospace -F _rvm_cd_complete cd fi fi