Skip to content

Instantly share code, notes, and snippets.

@hugomaiavieira
Created November 3, 2012 14:49
Show Gist options
  • Save hugomaiavieira/4007559 to your computer and use it in GitHub Desktop.
Save hugomaiavieira/4007559 to your computer and use it in GitHub Desktop.
Oh My Gems! Gemsets made easy and error free (http://blog.zenspider.com/blog/2012/09/ohmygems.html)
# This is basically the same Ryan Davis's script
# (http://blog.zenspider.com/blog/2012/09/ohmygems.html) with a bug fix and some
# modifications.
#
# This should be added after rbenv config lines on your .profile or .bashrc file.
#
export ORIG_GEM_PATH=${GEM_PATH:-}
export ORIG_GEM_HOME=${GEM_HOME:-}
export ORIG_PATH=${PATH}
ohmygems() {
name=${1:-}
if [ -z "$name" ]; then
echo "usage: ohmygems <name or reset>"
echo
echo " Switches gem home to a (potentially new) named repo."
echo " Your previous gems are still visible,"
echo " but new gem installs will install into ~/.gems/repos/<name>."
echo " Use 'reset' to go back to normal."
echo
echo "Available repos:"
echo
ls ~/.gem/repos | pr -o2 -l1
echo
return
elif [ $name = "reset" ]; then
echo Resetting repo
if [ -z "$ORIG_GEM_HOME" ]; then
unset GEM_HOME
else
GEM_HOME=${ORIG_GEM_HOME}
fi
GEM_PATH=${ORIG_GEM_PATH}
PATH=$ORIG_PATH
else
echo Switching to $name
export OMG_REPO=$name # for $PS1 use
export GEM_HOME=~/.gem/repos/${name}
export GEM_PATH=${ORIG_GEM_HOME}:${ORIG_GEM_PATH}
export PATH=${GEM_HOME}/bin:${ORIG_PATH} # the order matters
fi
}
alias omg=ohmygems
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment