Skip to content

Instantly share code, notes, and snippets.

@saevarom
Last active December 21, 2015 06:59
Show Gist options
  • Save saevarom/6267645 to your computer and use it in GitHub Desktop.
Save saevarom/6267645 to your computer and use it in GitHub Desktop.

Automatically use rvm from a file called .rvm within a folder. Sample contents for .rvm file:

2.0.0@mygemset

Automatically switch to virtualenv using a name from a file called .venv in a folder. Simply write the name of the virtual environment to the .venv file.

Automatically source env variables from a file called .exports Must have valid bash syntax:

export AWS_SECRET_KEY="blah-blah-blah"
has_rvm() {
if [ -e .rvm ]; then
RVM_TO_USE=`cat .rvm`
rvm use $RVM_TO_USE
fi
}
has_virtualenv() {
if [ -e .venv ]; then
VENV=`cat .venv`
echo -e "\x1B[01;32mSwitching to virtualenv $VENV\x1B[00m"
workon $VENV
fi
}
has_exports() {
if [ -e .exports ]; then
echo -e "\x1B[01;32mExporting env variables from .exports\x1B[00m"
source .exports
fi
}
venv_cd () {
builtin cd "$@" && has_virtualenv && has_exports && has_rvm
}
alias cd="venv_cd"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment