Skip to content
This repository

adding rbenv support to all the rvm themes #860

Merged
merged 1 commit into from about 2 years ago

5 participants

S. Brent Faulkner Jeff Dutil Jarin Udom Ori Peleg Robby Russell
S. Brent Faulkner

I've updated all the themes that reference rvm to also support rbenv...

(I hope it's considered useful so that I can switch back to origin instead of my own fork)

Robby Russell robbyrussell merged commit b56e372 into from January 25, 2012
Robby Russell robbyrussell closed this January 25, 2012
Robby Russell robbyrussell merged commit 6496acf into from January 25, 2012
Robby Russell robbyrussell closed this January 25, 2012
Ori Peleg

Most of these themes used to work without using rvm (or rbenv or the rbenv plugin) at all, because the ruby path string was just an empty string.
Now they fail with #878:

command not found: rbenv_prompt_info

Perhaps provide an empty rbenv_prompt_info using something like this?

functions rbenv_prompt_info >& /dev/null || rbenv_prompt_info() {}

I've submitted pull request #922 with a fix for this

I tried your fix from pull request #922 and it still doesn't work (at least with the superjarin theme).

If I comment out the changes, it works. Would it be better to replace the RVM test with:

if [ -e ~/.rvm/bin/rvm-prompt ]; then

I just tried it with if [ -e ~/.rvm/bin/rvm-prompt ]; then and it works for me. I don't have rbenv installed, so I don't know if that part works.

what does "it still doesn't work" mean? when I try it on my machine it seems fine... what is the result and what is the expected result?

It shows the prompt:

~ 

Instead of the expected prompt:

[ruby-1.8.7] ~ 

Using the alternative test for rvm-prompt's existence fixed it.

Sorry, but, I'm a bit confused by description of the problem. When I comment out the code that I added, ie. so all that's there is the original JARIN_CURRENT_RUBY_="..." line, I get the following (provided that rvm is not available)...

zsh: no such file or directory: /Users/brent.faulkner/.rvm/bin/rvm-prompt                                                         
[] ~ 

What plugins do you have enabled? and do you have rvm installed or not? (it's good you have a workaround, but I want to look at the larger issue and make sure it gets fixed properly everywhere)

btw... the pull request #922 was to fix a slightly different problem (if I understand yours correctly), the problem reported by @orip was command not found: rbenv_prompt_info, while yours seems rvm-related

that said, it would be good to fix this one too, so let me know regarding the above-asked questions...

cheers

Ah, yes I used the solution from nebirhos.zsh-theme. Instead of if which rvm-prompt &> /dev/null; then I used if [ -e ~/.rvm/bin/rvm-prompt ]; then and it works for me.

I do have RVM installed, and here are the plugins I'm using:

plugins=(rails git git-flow textmate ruby brew gem mysql)

I think that the problem might be that which rvm-prompt &> /dev/null is returning false even if you have RVM installed, which is causing it to skip down to the rbenv section. Can you try using if [ -e ~/.rvm/bin/rvm-prompt ]; then and see if that works?

I've updated pull request #922 to include an extra commit that should address this

cheers

Awesome, thanks :)

@sbfaulkner your fix in #922 didn't address all of the themes that were originally edited so I've opened #964 to fix the others I found that needed to be updated with the fix, which did fix the theme I was using.

actually, the problem you're fixing, while very similar is not quite the same... the ones that I fixed were the ones that had hard-coded paths - you are fixing the ones that assume that rvm-prompt is in the path

that said, I appreciate the fact that you are actually providing a fix (rather than just reporting the problem :-)

Oh my bad well I didn't read through everything going on here so that's what I get for assuming. Regardless I was having an issue with the theme I was using that was related to this change, and implementing the fix you had done for the other themes fixed my theme as well.

Michele Campeotto micampe referenced this pull request from a commit August 04, 2012
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jan 23, 2012
S. Brent Faulkner adding rbenv support to all the rvm themes 6496acf
This page is out of date. Refresh to see the latest.
10  themes/alanpeabody.zsh-theme
... ...
@@ -1,7 +1,14 @@
1 1
 
2 2
 local user='%{$fg[magenta]%}%n@%{$fg[magenta]%}%m%{$reset_color%}'
3 3
 local pwd='%{$fg[blue]%}%~%{$reset_color%}'
4  
-local rvm='%{$fg[green]%}‹$(rvm-prompt i v g)›%{$reset_color%}'
  4
+local rvm=''
  5
+if which rvm-prompt &> /dev/null; then
  6
+  rvm='%{$fg[green]%}‹$(rvm-prompt i v g)›%{$reset_color%}'
  7
+else
  8
+  if which rbenv &> /dev/null; then
  9
+    rvm='%{$fg[green]%}‹$(rbenv version | sed -e "s/ (set.*$//")›%{$reset_color%}'
  10
+  fi
  11
+fi
5 12
 local return_code='%(?..%{$fg[red]%}%? ↵%{$reset_color%})'
6 13
 local git_branch='$(git_prompt_status)%{$reset_color%}$(git_prompt_info)%{$reset_color%}'
7 14
 
@@ -19,4 +26,3 @@ ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[cyan]%} ✭"
19 26
 
20 27
 PROMPT="${user} ${pwd}$ "
21 28
 RPROMPT="${return_code} ${git_branch} ${rvm}"
22  
-
9  themes/bira.zsh-theme
@@ -3,7 +3,14 @@ local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
3 3
 
4 4
 local user_host='%{$terminfo[bold]$fg[green]%}%n@%m%{$reset_color%}'
5 5
 local current_dir='%{$terminfo[bold]$fg[blue]%} %~%{$reset_color%}'
6  
-local rvm_ruby='%{$fg[red]%}‹$(rvm-prompt i v g)›%{$reset_color%}'
  6
+local rvm_ruby=''
  7
+if which rvm-prompt &> /dev/null; then
  8
+  rvm_ruby='%{$fg[red]%}‹$(rvm-prompt i v g)›%{$reset_color%}'
  9
+else
  10
+  if which rbenv &> /dev/null; then
  11
+    rvm_ruby='%{$fg[red]%}‹$(rbenv version | sed -e "s/ (set.*$//")›%{$reset_color%}'
  12
+  fi
  13
+fi
7 14
 local git_branch='$(git_prompt_info)%{$reset_color%}'
8 15
 
9 16
 PROMPT="╭─${user_host} ${current_dir} ${rvm_ruby} ${git_branch}
8  themes/crunch.zsh-theme
@@ -29,7 +29,13 @@ ZSH_THEME_GIT_PROMPT_DIRTY=" $CRUNCH_GIT_DIRTY_COLOR✗"
29 29
 
30 30
 # Our elements:
31 31
 CRUNCH_TIME_="$CRUNCH_BRACKET_COLOR{$CRUNCH_TIME_COLOR%T$CRUNCH_BRACKET_COLOR}%{$reset_color%}"
32  
-CRUNCH_RVM_="$CRUNCH_BRACKET_COLOR"["$CRUNCH_RVM_COLOR\${\$(~/.rvm/bin/rvm-prompt i v g)#ruby-}$CRUNCH_BRACKET_COLOR"]"%{$reset_color%}"
  32
+if which rvm-prompt &> /dev/null; then
  33
+  CRUNCH_RVM_="$CRUNCH_BRACKET_COLOR"["$CRUNCH_RVM_COLOR\${\$(~/.rvm/bin/rvm-prompt i v g)#ruby-}$CRUNCH_BRACKET_COLOR"]"%{$reset_color%}"
  34
+else
  35
+  if which rbenv &> /dev/null; then
  36
+    CRUNCH_RVM_="$CRUNCH_BRACKET_COLOR"["$CRUNCH_RVM_COLOR\${\$(rbenv version | sed -e 's/ (set.*$//' -e 's/^ruby-//')}$CRUNCH_BRACKET_COLOR"]"%{$reset_color%}"
  37
+  fi
  38
+fi
33 39
 CRUNCH_DIR_="$CRUNCH_DIR_COLOR%~\$(git_prompt_info) "
34 40
 CRUNCH_PROMPT="$CRUNCH_BRACKET_COLOR➭ "
35 41
 
8  themes/dallas.zsh-theme
@@ -3,7 +3,13 @@
3 3
 # Grab the current date (%D) and time (%T) wrapped in {}: {%D %T}
4 4
 DALLAS_CURRENT_TIME_="%{$fg[white]%}{%{$fg[yellow]%}%D %T%{$fg[white]%}}%{$reset_color%}"
5 5
 # Grab the current version of ruby in use (via RVM): [ruby-1.8.7]
6  
-DALLAS_CURRENT_RUBY_="%{$fg[white]%}[%{$fg[magenta]%}\$(~/.rvm/bin/rvm-prompt i v)%{$fg[white]%}]%{$reset_color%}"
  6
+if which rvm-prompt &> /dev/null; then
  7
+  DALLAS_CURRENT_RUBY_="%{$fg[white]%}[%{$fg[magenta]%}\$(~/.rvm/bin/rvm-prompt i v)%{$fg[white]%}]%{$reset_color%}"
  8
+else
  9
+  if which rbenv &> /dev/null; then
  10
+    DALLAS_CURRENT_RUBY_="%{$fg[white]%}[%{$fg[magenta]%}\$(rbenv version | sed -e 's/ (set.*$//')%{$fg[white]%}]%{$reset_color%}"
  11
+  fi
  12
+fi
7 13
 # Grab the current machine name: muscato
8 14
 DALLAS_CURRENT_MACH_="%{$fg[green]%}%m%{$fg[white]%}:%{$reset_color%}"
9 15
 # Grab the current filepath, use shortcuts: ~/Desktop
4  themes/eastwood.zsh-theme
... ...
@@ -1,6 +1,10 @@
1 1
 #RVM settings
2 2
 if [[ -s ~/.rvm/scripts/rvm ]] ; then 
3 3
   RPS1="%{$fg[yellow]%}rvm:%{$reset_color%}%{$fg[red]%}\$(~/.rvm/bin/rvm-prompt)%{$reset_color%} $EPS1"
  4
+else
  5
+  if which rbenv &> /dev/null; then
  6
+    RPS1="%{$fg[yellow]%}rbenv:%{$reset_color%}%{$fg[red]%}\$(rbenv version | sed -e 's/ (set.*$//')%{$reset_color%} $EPS1"
  7
+  fi
4 8
 fi
5 9
 
6 10
 ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}["
9  themes/fino.zsh-theme
@@ -25,7 +25,14 @@ function box_name {
25 25
 }
26 26
 
27 27
 
28  
-local rvm_ruby='‹$(rvm-prompt i v g)›%{$reset_color%}'
  28
+local rvm_ruby=''
  29
+if which rvm-prompt &> /dev/null; then
  30
+  rvm_ruby='‹$(rvm-prompt i v g)›%{$reset_color%}'
  31
+else
  32
+  if which rbenv &> /dev/null; then
  33
+    rvm_ruby='‹$(rbenv version | sed -e "s/ (set.*$//")›%{$reset_color%}'
  34
+  fi
  35
+fi
29 36
 local current_dir='${PWD/#$HOME/~}'
30 37
 local git_info='$(git_prompt_info)'
31 38
 
6  themes/gallois.zsh-theme
@@ -15,7 +15,11 @@ git_custom_status() {
15 15
 if [[ -s ~/.rvm/scripts/rvm ]] ; then 
16 16
   RPS1='$(git_custom_status)%{$fg[red]%}[`~/.rvm/bin/rvm-prompt`]%{$reset_color%} $EPS1'
17 17
 else
18  
-  RPS1='$(git_custom_status) $EPS1'
  18
+  if which rbenv &> /dev/null; then
  19
+    RPS1='$(git_custom_status)%{$fg[red]%}[`rbenv version | sed -e "s/ (set.*$//"`]%{$reset_color%} $EPS1'
  20
+  else
  21
+    RPS1='$(git_custom_status) $EPS1'
  22
+  fi
19 23
 fi
20 24
 
21 25
 PROMPT='%{$fg[cyan]%}[%~% ]%(?.%{$fg[green]%}.%{$fg[red]%})%B$%b '
4  themes/jonathan.zsh-theme
@@ -10,7 +10,7 @@ function theme_precmd {
10 10
     PR_PWDLEN=""
11 11
 
12 12
     local promptsize=${#${(%):---(%n@%m:%l)---()--}}
13  
-    local rubyprompt=`rvm_prompt_info`
  13
+    local rubyprompt=`rvm_prompt_info || rbenv_prompt_info`
14 14
     local rubypromptsize=${#${rubyprompt}}
15 15
     local pwdsize=${#${(%):-%~}}
16 16
 
@@ -113,7 +113,7 @@ setprompt () {
113 113
     PROMPT='$PR_SET_CHARSET$PR_STITLE${(e)PR_TITLEBAR}\
114 114
 $PR_CYAN$PR_SHIFT_IN$PR_ULCORNER$PR_HBAR$PR_SHIFT_OUT$PR_GREY(\
115 115
 $PR_GREEN%$PR_PWDLEN<...<%~%<<\
116  
-$PR_GREY)`rvm_prompt_info`$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_HBAR${(e)PR_FILLBAR}$PR_HBAR$PR_SHIFT_OUT$PR_GREY(\
  116
+$PR_GREY)`rvm_prompt_info || rbenv_prompt_info`$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_HBAR${(e)PR_FILLBAR}$PR_HBAR$PR_SHIFT_OUT$PR_GREY(\
117 117
 $PR_CYAN%(!.%SROOT%s.%n)$PR_GREY@$PR_GREEN%m:%l\
118 118
 $PR_GREY)$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_URCORNER$PR_SHIFT_OUT\
119 119
 
4  themes/josh.zsh-theme
@@ -10,7 +10,7 @@ function josh_prompt {
10 10
   prompt=" "
11 11
 
12 12
   branch=$(current_branch)
13  
-  ruby_version=$(rvm_prompt_info)
  13
+  ruby_version=$(rvm_prompt_info || rbenv_prompt_info)
14 14
   path_size=${#PWD}
15 15
   branch_size=${#branch}
16 16
   ruby_size=${#ruby_version}
@@ -31,7 +31,7 @@ function josh_prompt {
31 31
     prompt=" $prompt"
32 32
   done
33 33
   
34  
-  prompt="%{%F{green}%}$PWD$prompt%{%F{red}%}$(rvm_prompt_info)%{$reset_color%} $(git_prompt_info)"
  34
+  prompt="%{%F{green}%}$PWD$prompt%{%F{red}%}$(rvm_prompt_info || rbenv_prompt_info)%{$reset_color%} $(git_prompt_info)"
35 35
   
36 36
   echo $prompt
37 37
 }
9  themes/macovsky-ruby.zsh-theme
... ...
@@ -1,7 +1,14 @@
1 1
 # ZSH Theme - Preview: http://gyazo.com/8becc8a7ed5ab54a0262a470555c3eed.png
2 2
 local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
3 3
 
4  
-PROMPT='%{$fg[green]%}%~%{$reset_color%} %{$fg[red]%}‹$(~/.rvm/bin/rvm-prompt i v)› %{$reset_color%} $(git_prompt_info)%{$reset_color%}%B$%b '
  4
+if which rvm-prompt &> /dev/null; then
  5
+  PROMPT='%{$fg[green]%}%~%{$reset_color%} %{$fg[red]%}‹$(~/.rvm/bin/rvm-prompt i v)› %{$reset_color%} $(git_prompt_info)%{$reset_color%}%B$%b '
  6
+else
  7
+  if which rbenv &> /dev/null; then
  8
+    PROMPT='%{$fg[green]%}%~%{$reset_color%} %{$fg[red]%}‹$(rbenv version | sed -e "s/ (set.*$//")› %{$reset_color%} $(git_prompt_info)%{$reset_color%}%B$%b '
  9
+  fi
  10
+fi
  11
+
5 12
 RPS1="${return_code}"
6 13
 
7 14
 ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[yellow]%}‹"
8  themes/macovsky.zsh-theme
... ...
@@ -1,7 +1,13 @@
1 1
 # ZSH Theme - Preview: http://gyazo.com/8becc8a7ed5ab54a0262a470555c3eed.png
2 2
 local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
3 3
 
4  
-PROMPT='%{$fg[green]%}%~%{$reset_color%} %{$fg[red]%}‹$(~/.rvm/bin/rvm-prompt i v)› %{$reset_color%} $(git_prompt_info)%{$reset_color%}%B$%b '
  4
+if which rvm-prompt &> /dev/null; then
  5
+  PROMPT='%{$fg[green]%}%~%{$reset_color%} %{$fg[red]%}‹$(~/.rvm/bin/rvm-prompt i v)› %{$reset_color%} $(git_prompt_info)%{$reset_color%}%B$%b '
  6
+else
  7
+  if which rbenv &> /dev/null; then
  8
+    PROMPT='%{$fg[green]%}%~%{$reset_color%} %{$fg[red]%}‹$(rbenv version | sed -e "s/ (set.*$//")› %{$reset_color%} $(git_prompt_info)%{$reset_color%}%B$%b '
  9
+  fi
  10
+fi
5 11
 RPS1="${return_code}"
6 12
 
7 13
 ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[yellow]%}‹"
2  themes/murilasso.zsh-theme
... ...
@@ -1,7 +1,7 @@
1 1
 local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
2 2
 local user_host='%{$terminfo[bold]$fg[green]%}%n@%m%{$reset_color%}'
3 3
 local current_dir='%{$terminfo[bold]$fg[blue]%}%~%{$reset_color%}'
4  
-local rvm_ruby='%{$fg[red]%}$(rvm_prompt_info)%{$reset_color%}'
  4
+local rvm_ruby='%{$fg[red]%}$(rvm_prompt_info || rbenv_prompt_info)%{$reset_color%}'
5 5
 local git_branch='%{$fg[blue]%}$(git_prompt_info)%{$reset_color%}'
6 6
 
7 7
 PROMPT="${user_host}:${current_dir} ${rvm_ruby}
4  themes/nebirhos.zsh-theme
@@ -4,6 +4,10 @@
4 4
 # Get the current ruby version in use with RVM:
5 5
 if [ -e ~/.rvm/bin/rvm-prompt ]; then
6 6
     RUBY_PROMPT_="%{$fg_bold[blue]%}rvm:(%{$fg[green]%}\$(~/.rvm/bin/rvm-prompt s i v g)%{$fg_bold[blue]%})%{$reset_color%} "
  7
+else
  8
+  if which rbenv &> /dev/null; then
  9
+    RUBY_PROMPT_="%{$fg_bold[blue]%}rvm:(%{$fg[green]%}\$(rbenv version | sed -e 's/ (set.*$//')%{$fg_bold[blue]%})%{$reset_color%} "
  10
+  fi
7 11
 fi
8 12
 
9 13
 # Get the host name (first 4 chars)
8  themes/superjarin.zsh-theme
... ...
@@ -1,5 +1,11 @@
1 1
 # Grab the current version of ruby in use (via RVM): [ruby-1.8.7]
2  
-JARIN_CURRENT_RUBY_="%{$fg[white]%}[%{$fg[red]%}\$(~/.rvm/bin/rvm-prompt i v)%{$fg[white]%}]%{$reset_color%}"
  2
+if which rvm-prompt &> /dev/null; then
  3
+  JARIN_CURRENT_RUBY_="%{$fg[white]%}[%{$fg[red]%}\$(~/.rvm/bin/rvm-prompt i v)%{$fg[white]%}]%{$reset_color%}"
  4
+else
  5
+  if which rbenv &> /dev/null; then
  6
+    JARIN_CURRENT_RUBY_="%{$fg[white]%}[%{$fg[red]%}\$(rbenv version | sed -e 's/ (set.*$//')%{$fg[white]%}]%{$reset_color%}"
  7
+  fi
  8
+fi
3 9
 
4 10
 # Grab the current filepath, use shortcuts: ~/Desktop
5 11
 # Append the current git branch, if in a git repository
9  themes/suvash.zsh-theme
@@ -12,8 +12,15 @@ function collapse_pwd {
12 12
     echo $(pwd | sed -e "s,^$HOME,~,")
13 13
 }
14 14
 
15  
-PROMPT='%{$fg[magenta]%}%n%{$reset_color%} at %{$fg[yellow]%}%m%{$reset_color%} in %{$fg_bold[green]%}${PWD/#$HOME/~}%{$reset_color%}$(git_prompt_info) using %{$reset_color%}%{$fg[red]%}$(~/.rvm/bin/rvm-prompt)%{$reset_color%} 
  15
+if which rvm-prompt &> /dev/null; then
  16
+  PROMPT='%{$fg[magenta]%}%n%{$reset_color%} at %{$fg[yellow]%}%m%{$reset_color%} in %{$fg_bold[green]%}${PWD/#$HOME/~}%{$reset_color%}$(git_prompt_info) using %{$reset_color%}%{$fg[red]%}$(~/.rvm/bin/rvm-prompt)%{$reset_color%} 
16 17
 $(virtualenv_info)$(prompt_char) '
  18
+else
  19
+  if which rbenv &> /dev/null; then
  20
+    PROMPT='%{$fg[magenta]%}%n%{$reset_color%} at %{$fg[yellow]%}%m%{$reset_color%} in %{$fg_bold[green]%}${PWD/#$HOME/~}%{$reset_color%}$(git_prompt_info) using %{$reset_color%}%{$fg[red]%}$(rbenv version | sed -e "s/ (set.*$//")%{$reset_color%} 
  21
+$(virtualenv_info)$(prompt_char) '
  22
+  fi
  23
+fi
17 24
 
18 25
 
19 26
 ZSH_THEME_GIT_PROMPT_PREFIX=" on %{$fg[magenta]%}"
2  themes/wuffers.zsh-theme
@@ -2,4 +2,4 @@ ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}["
2 2
 ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%} "
3 3
 ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg_bold[red]%} x%{$fg_bold[blue]%}"
4 4
 
5  
-PROMPT='%{$(git_prompt_info)%}%{$fg_bold[green]%}{%{$(rvm current)%}}%{$reset_color%} %{$fg[cyan]%}%c%{$reset_color%} '
  5
+PROMPT='%{$(git_prompt_info)%}%{$fg_bold[green]%}{%{$(rvm current 2>/dev/null || rbenv version-name 2>/dev/null)%}}%{$reset_color%} %{$fg[cyan]%}%c%{$reset_color%} '
10  themes/zhann.zsh-theme
... ...
@@ -1,5 +1,13 @@
1 1
 PROMPT='%{$fg_bold[green]%}%p %{$fg[cyan]%}%c%{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'
2  
-RPROMPT='%{$reset_color%} %{$fg[red]%}$(~/.rvm/bin/rvm-prompt i v g) %{$reset_color%}'
  2
+
  3
+if which rvm-prompt &> /dev/null; then
  4
+  RPROMPT='%{$reset_color%} %{$fg[red]%}$(~/.rvm/bin/rvm-prompt i v g) %{$reset_color%}'
  5
+else
  6
+  if which rbenv &> /dev/null; then
  7
+    RPROMPT='%{$reset_color%} %{$fg[red]%}$(rbenv version | sed -e "s/ (set.*$//") %{$reset_color%}'
  8
+  fi
  9
+fi
  10
+
3 11
 
4 12
 ZSH_THEME_GIT_PROMPT_PREFIX=" (%{$fg[red]%}"
5 13
 ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.