From 138fe8f2ffa6db830b455f4d165acb9257409fae Mon Sep 17 00:00:00 2001 From: Stephen Eley Date: Mon, 10 Oct 2011 14:25:01 -0400 Subject: [PATCH] Intelligently select between RVM and rbenv --- themes/crunch.zsh-theme | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/themes/crunch.zsh-theme b/themes/crunch.zsh-theme index 2473cd230..189d964ab 100644 --- a/themes/crunch.zsh-theme +++ b/themes/crunch.zsh-theme @@ -1,15 +1,15 @@ # CRUNCH - created from Steve Eley's cat waxing. # Initially hacked from the Dallas theme. Thanks, Dallas Reedy. # -# This theme assumes you do most of your oh-my-zsh'ed "colorful" work at a single machine, -# and eschews the standard space-consuming user and hostname info. Instead, only the +# This theme assumes you do most of your oh-my-zsh'ed "colorful" work at a single machine, +# and eschews the standard space-consuming user and hostname info. Instead, only the # things that vary in my own workflow are shown: # # * The time (not the date) # * The RVM version and gemset (omitting the 'ruby' name if it's MRI) # * The current directory # * The Git branch and its 'dirty' state -# +# # Colors are at the top so you can mess with those separately if you like. # For the most part I stuck with Dallas's. @@ -27,11 +27,22 @@ ZSH_THEME_GIT_PROMPT_SUFFIX="" ZSH_THEME_GIT_PROMPT_CLEAN=" $CRUNCH_GIT_CLEAN_COLOR✓" ZSH_THEME_GIT_PROMPT_DIRTY=" $CRUNCH_GIT_DIRTY_COLOR✗" +# Intelligently show Ruby version if the 'rbenv' or 'rvm' plugins are active. +for plugin ($plugins); do + if [[ $plugin = 'rvm' ]]; then + CRUNCH_RUBY_VERSION="\${\$(rvm-prompt i v g)#ruby-}" + elif [[ $plugin = 'rbenv' ]]; then + CRUNCH_RUBY_VERSION="\${\$(rbenv_prompt_info)%%-*}" + fi +done + # Our elements: CRUNCH_TIME_="$CRUNCH_BRACKET_COLOR{$CRUNCH_TIME_COLOR%T$CRUNCH_BRACKET_COLOR}%{$reset_color%}" -CRUNCH_RVM_="$CRUNCH_BRACKET_COLOR"["$CRUNCH_RVM_COLOR\${\$(~/.rvm/bin/rvm-prompt i v g)#ruby-}$CRUNCH_BRACKET_COLOR"]"%{$reset_color%}" +if [[ -n $CRUNCH_RUBY_VERSION ]]; then + CRUNCH_RUBY_="$CRUNCH_BRACKET_COLOR"["$CRUNCH_RVM_COLOR$CRUNCH_RUBY_VERSION$CRUNCH_BRACKET_COLOR"]"%{$reset_color%}" +fi CRUNCH_DIR_="$CRUNCH_DIR_COLOR%~\$(git_prompt_info) " CRUNCH_PROMPT="$CRUNCH_BRACKET_COLOR➭ " # Put it all together! -PROMPT="$CRUNCH_TIME_$CRUNCH_RVM_$CRUNCH_DIR_$CRUNCH_PROMPT%{$reset_color%}" +PROMPT="$CRUNCH_TIME_$CRUNCH_RUBY_$CRUNCH_DIR_$CRUNCH_PROMPT%{$reset_color%}"