Skip to content
This repository
branch: master
executable file 83 lines (79 sloc) 2.925 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
#!/usr/bin/env bash

# Source a .rvmrc file in a directory after changing to it, if it exists. To
# disable this feature, set rvm_project_rvmrc=0 in /etc/rvmrc or $HOME/.rvmrc
case "${rvm_project_rvmrc:-1}" in
1|cd)
  # clonned from git@github.com:mpapis/bash_zsh_support.git
  source "$rvm_scripts_path/extras/bash_zsh_support/chpwd/function.sh"

  # not using default loadign to support older Zsh
  [[ -n "${ZSH_VERSION:-}" ]] &&
  __rvm_version_compare "$ZSH_VERSION" -gt 4.3.4 ||
  {
    cd() { __zsh_like_cd cd "$@" ; }
    popd() { __zsh_like_cd popd "$@" ; }
    pushd() { __zsh_like_cd pushd "$@" ; }
  }

  __rvm_after_cd()
  {
    typeset rvm_hook
    rvm_hook="after_cd"
    if [[ -n "${rvm_scripts_path:-}" || -n "${rvm_path:-}" ]]
    then source "${rvm_scripts_path:-$rvm_path/scripts}/hook"
    fi
  }
  __rvm_cd_functions_set()
  {
    __rvm_do_with_env_before
    __rvm_project_rvmrc >&2 || true
__rvm_do_with_env_after
    return 0
  }
  export -a chpwd_functions
  [[ " ${chpwd_functions[*]} " == *" __rvm_cd_functions_set "* ]] ||
  chpwd_functions=( "${chpwd_functions[@]}" __rvm_cd_functions_set )
  [[ " ${chpwd_functions[*]} " == *" __rvm_after_cd "* ]] ||
  chpwd_functions=( "${chpwd_functions[@]}" __rvm_after_cd )

  # This functionality is opt-in by setting rvm_cd_complete_flag=1 in ~/.rvmrc
  # Generic bash cd completion seems to work great for most, so this is only
  # for those that have some issues with that.
  if (( ${rvm_cd_complete_flag:-0} == 1 ))
  then
    # 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 ()
    {
      typeset directory current matches item index sep
      sep="${IFS}"
      export IFS
      IFS=$'\n'
      COMPREPLY=()
      current="${COMP_WORDS[COMP_CWORD]}"
      if [[ -n "$CDPATH" && ${current:0:1} != "/" ]] ; then
        index=0
        # The change to IFS above means that the \tr below should replace ':'
        # with a newline rather than a space. A space would be ignored, breaking
        # TAB completion based on CDPATH again
        for directory in $(printf "%b" "$CDPATH" | \tr -s ':' '\n') ; do
          for item in $( compgen -d "$directory/$current" ) ; do
            COMPREPLY[index++]=${item#$directory/}
          done
        done
      else
        COMPREPLY=( $(compgen -d ${current}) )
      fi
      IFS="${sep}";
    }
    complete -o bashdefault -o default -o filenames -o dirnames -o nospace -F _rvm_cd_complete cd
fi
  ;;
2|prompt)
  if
    [[ -n "${ZSH_VERSION:-}" ]]
  then
    precmd_functions+=(__rvm_do_with_env_before __rvm_project_rvmrc __rvm_do_with_env_after)
  else
    PROMPT_COMMAND="${PROMPT_COMMAND:-}${PROMPT_COMMAND:+; }__rvm_do_with_env_before; __rvm_project_rvmrc; __rvm_do_with_env_after"
  fi
  ;;
esac
Something went wrong with that request. Please try again.