1 # This plugin loads rbenv into the current shell and provides prompt info via
2 # the 'rbenv_prompt_info' function.
4 FOUND_RBENV=$+commands[rbenv]
6 if [[ $FOUND_RBENV -ne 1 ]]; then
7 rbenvdirs=("$HOME/.rbenv" "/usr/local/rbenv" "/opt/rbenv" "/usr/local/opt/rbenv")
8 for dir in $rbenvdirs; do
9 if [[ -d $dir/bin ]]; then
10 export PATH="$dir/bin:$PATH"
17 if [[ $FOUND_RBENV -ne 1 ]]; then
18 if (( $+commands[brew] )) && dir=$(brew --prefix rbenv 2>/dev/null); then
19 if [[ -d $dir/bin ]]; then
20 export PATH="$dir/bin:$PATH"
26 if [[ $FOUND_RBENV -eq 1 ]]; then
27 eval "$(rbenv init --no-rehash - zsh)"
29 alias rubies="rbenv versions"
30 alias gemsets="rbenv gemset list"
32 function current_ruby() {
33 echo "$(rbenv version-name)"
36 function current_gemset() {
37 echo "$(rbenv gemset active 2>/dev/null)" | tr ' ' '+'
41 local rbenv_path=$(rbenv prefix)
42 gem list $@ | sed -E \
43 -e "s/\([0-9a-z, \.]+( .+)?\)/$fg[blue]&$reset_color/g" \
44 -e "s|$(echo $rbenv_path)|$fg[magenta]\$rbenv_path$reset_color|g" \
45 -e "s/$current_ruby@global/$fg[yellow]&$reset_color/g" \
46 -e "s/$current_ruby$current_gemset$/$fg[green]&$reset_color/g"
49 function rbenv_prompt_info() {
50 local ruby=${$(current_ruby):gs/%/%%} gemset=${$(current_gemset):gs/%/%%}
51 echo -n "${ZSH_THEME_RUBY_PROMPT_PREFIX}"
52 [[ -n "$gemset" ]] && echo -n "${ruby}@${gemset}" || echo -n "${ruby}"
53 echo "${ZSH_THEME_RUBY_PROMPT_SUFFIX}"
56 alias rubies="ruby -v"
57 function gemsets() { echo "not supported" }
58 function current_ruby() { echo "not supported" }
59 function current_gemset() { echo "not supported" }
60 function gems() { echo "not supported" }
61 function rbenv_prompt_info() {
62 echo -n "${ZSH_THEME_RUBY_PROMPT_PREFIX}"
63 echo -n "system: $(ruby -v | cut -f-2 -d ' ' | sed 's/%/%%/g')"
64 echo "${ZSH_THEME_RUBY_PROMPT_SUFFIX}"
68 unset FOUND_RBENV rbenvdirs dir