Skip to content

Instantly share code, notes, and snippets.

@dmitryd
Last active October 12, 2015 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitryd/a364f09545c6eda0ed48 to your computer and use it in GitHub Desktop.
Save dmitryd/a364f09545c6eda0ed48 to your computer and use it in GitHub Desktop.
This little shell function allows to set environment variables when you cd into that directory.
# Note: this is just a fragment that you should put in your ~/.bash_profile
# Tested on Mac only!
#
# If you want a more sophisticated and feature rich solution here are some pointers:
# - https://github.com/cxreg/smartcd
# - http://swapoff.org/ondir.html
function cd_ {
if [ -e .env_off ] ; then
. .env_off
fi
builtin cd "$*"
if [ -e .env ] ; then
. .env
fi
}
alias cd=cd_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment