Permalink
Browse files

Feature: rvm_cd_complete_flag for ~/.rvmrc.

  • Loading branch information...
1 parent c3d69c9 commit f856e3c8f50168776d7dd8edd7edc052c9402591 @wayneeseguin wayneeseguin committed Nov 16, 2010
Showing with 33 additions and 25 deletions.
  1. +33 −25 scripts/cd
View
@@ -45,32 +45,40 @@ if [[ ${rvm_project_rvmrc:-1} -ne 0 ]] ; then
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
- # 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 "%s" "$CDPATH" | tr -s ':' '\n') ; do
- for item in $( compgen -d "$directory/$current" ) ; do
- COMPREPLY[index++]=${item#$directory/}
+ # 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} = 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 ()
+ {
+ 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
+ # 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 "%s" "$CDPATH" | tr -s ':' '\n') ; do
+ for item in $( compgen -d "$directory/$current" ) ; do
+ COMPREPLY[index++]=${item#$directory/}
+ done
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
+ 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

0 comments on commit f856e3c

Please sign in to comment.