Direnv
I use this tool to set specific variables in my shell for different projects. For instance to set the AWS_PROFILE environment variable based on which client I am working for.
$ sudo apt install -y direnv
$ echo 'eval "$(direnv hook bash)"' >> .bashrc
# Now reload the shell
$ echo 'export AWS_PROFILE={client_name} > ~/Projects/{client_name}'
$ cd ~/Projects/{client_name}
$ direnv allow
# Now when you switch to the directory of the client you will see something like
$ cd ~/Projects/{client_name}
direnv: loading ~/Projects/{client_name}/.envrc
direnv: export +AWS_PROFILE
# And switching to different settings is just a matter of moving to the client directory.
When having parent en sub directory direnvs. You will unload the parent .envrc
when accessing the sub directory.
This can be fixed by adding source_up
to the .envrc
file of the subdirectory.