-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
cd
executable file
·98 lines (94 loc) · 3.02 KB
/
cd
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/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
if (( ${rvm_project_rvmrc:-1} > 0 ))
then
__rvm_setup_cd()
{
# try to use smartcd function, fallback to builtin
typeset __cd_prefix __command
if typeset -f smartcd >/dev/null 2>/dev/null
then __cd_prefix="smartcd"
else __cd_prefix="builtin"
fi
__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_setup_cd_function()
{
typeset __cd_prefix __command
__cd_prefix=$1
__command=$2
eval "
${__command}(){
if ${__cd_prefix} ${__command} \"\$@\"
then
[[ -n \"\${rvm_current_rvmrc:-""}\" && \"\$*\" == \".\" ]] && rvm_current_rvmrc=\"\" || true
__rvm_do_with_env_before
__rvm_project_rvmrc
__rvm_after_cd
__rvm_do_with_env_after
return 0
else
return \$?
fi
}"
}
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
export -a chpwd_functions
chpwd_functions=( "${chpwd_functions[@]}" __rvm_do_with_env_before __rvm_project_rvmrc __rvm_after_cd __rvm_do_with_env_after )
else
for __command in cd popd pushd
do __rvm_setup_cd_function "${__cd_prefix}" "${__command}"
done
fi
else
for __command in cd popd pushd
do __rvm_setup_cd_function "${__cd_prefix}" "${__command}"
done
fi
}
__rvm_setup_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
fi