From a5545bd31c76a4f34339dc4e7b87f74fa0174015 Mon Sep 17 00:00:00 2001 From: Peter Hoeg Date: Thu, 20 Oct 2011 14:12:56 +0800 Subject: [PATCH 1/2] add: rbenv plugin --- plugins/rbenv/rbenv.plugin.zsh | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 plugins/rbenv/rbenv.plugin.zsh diff --git a/plugins/rbenv/rbenv.plugin.zsh b/plugins/rbenv/rbenv.plugin.zsh new file mode 100644 index 000000000..136ea75e0 --- /dev/null +++ b/plugins/rbenv/rbenv.plugin.zsh @@ -0,0 +1,44 @@ +FOUND_RBENV=0 +for rbenvdir in "$HOME/.rbenv" "/usr/local/rbenv" "/opt/rbenv" ; do + if [ -d $rbenvdir/bin -a $FOUND_RBENV -eq 0 ] ; then + FOUND_RBENV=1 + export RBENV_ROOT=$rbenvdir + export PATH=${rbenvdir}/bin:$PATH + eval "$(rbenv init -)" + + alias rubies="rbenv versions" + alias gemsets="rbenv gemset list" + + function current_ruby() { + echo "$(rbenv version-name)" + } + + function current_gemset() { + echo "$(rbenv gemset active 2&>/dev/null | sed -e ":a" -e '$ s/\n/+/gp;N;b a') | head -n1" + } + + function gems { + local rbenv_path=$(rbenv prefix) + gem list $@ | sed \ + -Ee "s/\([0-9\.]+( .+)?\)/$fg[blue]&$reset_color/g" \ + -Ee "s|$(echo $rbenv_path)|$fg[magenta]\$rbenv_path$reset_color|g" \ + -Ee "s/$current_ruby@global/$fg[yellow]&$reset_color/g" \ + -Ee "s/$current_ruby$current_gemset$/$fg[green]&$reset_color/g" + } + + function rbenv_prompt_info() { + if [[ -n $(current_gemset) ]] ; then + echo "$(current_ruby)@$(current_gemset)" + else + echo "$(current_ruby)" + fi + } + fi +done +unset rbenvdir + +if [ $FOUND_RBENV -eq 0 ] ; then + alias rubies='ruby -v' + function gemsets() { echo 'not supported' } + function rbenv_prompt_info() { echo "system: $(ruby -v | cut -f-2 -d ' ')" } +fi From 31cddcd32427a5f5d3daa0da168d39aba5b510b4 Mon Sep 17 00:00:00 2001 From: Peter Hoeg Date: Thu, 20 Oct 2011 15:27:49 +0800 Subject: [PATCH 2/2] fix: rbenv: I need to find a proper way to test changes... --- plugins/rbenv/rbenv.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/rbenv/rbenv.plugin.zsh b/plugins/rbenv/rbenv.plugin.zsh index 136ea75e0..ae37404cd 100644 --- a/plugins/rbenv/rbenv.plugin.zsh +++ b/plugins/rbenv/rbenv.plugin.zsh @@ -14,7 +14,7 @@ for rbenvdir in "$HOME/.rbenv" "/usr/local/rbenv" "/opt/rbenv" ; do } function current_gemset() { - echo "$(rbenv gemset active 2&>/dev/null | sed -e ":a" -e '$ s/\n/+/gp;N;b a') | head -n1" + echo "$(rbenv gemset active 2&>/dev/null | sed -e ":a" -e '$ s/\n/+/gp;N;b a' | head -n1)" } function gems {