Skip to content

Instantly share code, notes, and snippets.

@ah45
Forked from blowmage/.profile
Last active August 29, 2015 14:01
Show Gist options
  • Save ah45/7dad9968dd2b1240b01d to your computer and use it in GitHub Desktop.
Save ah45/7dad9968dd2b1240b01d to your computer and use it in GitHub Desktop.
ohmygems
# configure the Ruby Gems environment
export RUBYOPT=rubygems
export GEM_HOME="$HOME/.gem"
export GEM_PATH="$HOME/.gem"
export PATH="$HOME/.gem/bin:$PATH"
source ~/bin/ohmygems
# -*- sh -*-
ohmygems() {
name=${1:-}
if [ -z "${ORIG_GEM_PATH:-}" ]; then
export ORIG_GEM_PATH=${GEM_PATH:-}
export ORIG_GEM_HOME=${GEM_HOME:-}
export ORIG_PATH=${PATH}
fi
if [ -z "$name" ]; then
echo "usage: ohmygems <name/. or reset or env>"
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 ~/.gem/repos/<name>."
echo " Use 'reset' to go back to normal."
echo " Use 'env' to view environment information."
echo " Use '.' to use the current directory name as the repo."
echo
echo "Available repos in ~/.gem/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
unset OMG_NAME
elif [ $name = "env" ]; then
echo Oh My Gems Environment
echo GEM_PATH=${GEM_PATH:-not set}
echo GEM_HOME=${GEM_HOME:-not set}
echo PATH=$PATH
else
if [ $name = "." ]; then
name=${PWD##*/}
fi
echo Switching to $name
export GEM_HOME=~/.gem/repos/${name}
export GEM_PATH=${ORIG_GEM_HOME}:${ORIG_GEM_PATH}
export PATH=${ORIG_PATH}:${GEM_HOME}/bin
[ -d $GEM_HOME ] || mkdir -p $GEM_HOME
OMG_NAME=${name}
fi
}
alias omg=ohmygems
@ah45
Copy link
Author

ah45 commented May 28, 2014

Added the ability to pass '.' as the repo name to use the current working directory without having to type it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment