Skip to content

Instantly share code, notes, and snippets.

@dry
Last active September 7, 2016 16:00
Show Gist options
  • Save dry/8267866 to your computer and use it in GitHub Desktop.
Save dry/8267866 to your computer and use it in GitHub Desktop.
Set/unset per directory environment variables for development projects
SHOPIFY_CLIENT_ID "123456789"
# Manage ENV files
ENV=.bashenv
function process_old_env()
{
FILE="$OLDPWD/$ENV"
if [ -e "$FILE" ]
then
while read _name _value
do
if [ -n "$_name" ]
then
unset "${_name^^}"
fi
done < "$FILE"
fi
}
function process_new_env()
{
FILE="$PWD/$ENV"
if [ -e "$FILE" ]
then
while read _name _value
do
if [ -n "$_name" ]
then
export "${_name^^}"="$_value"
fi
done < "$ENV"
fi
}
cd()
{
if builtin cd "$@"
then
process_old_env
process_new_env
return 0
else
return $?
fi
}
cd .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment