-
-
Save ah45/7dad9968dd2b1240b01d to your computer and use it in GitHub Desktop.
ohmygems
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added the ability to pass '.' as the repo name to use the current working directory without having to type it out.