Skip to content

Instantly share code, notes, and snippets.

@jcaromiq
Last active March 14, 2018 09:53
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 jcaromiq/e5c0079c9fd15db5c8f02d015596fe54 to your computer and use it in GitHub Desktop.
Save jcaromiq/e5c0079c9fd15db5c8f02d015596fe54 to your computer and use it in GitHub Desktop.
Hook to execute file with name .env.sh if exists when change directory
source_env() {
if [ ! -z "$1" ]; then
1=$(realpath $1)
if [[ "$1" != "/" ]]; then
source_env "$1/.."
env_file="$1/.env.sh"
if [[ -e $env_file ]]; then
source $env_file
fi
fi
fi
}
function chpwd() {
emulate -L zsh
source_env "."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment