Load environment variables like API keys or other (sensitive) settings you do not want to be set always into the current bash environment on demand.
Put something like this into you .bashrc
or .bash_profile
to load the snippet into your bash environment:
# Loader function (with completion) for *.env files in ~/.env/
source $HOME/.bash/loadenv.sh
Create a .env
directory in your home directory and make it only accessible to you (optional, but a good idea).
mkdir ~/.loadenv
chmod 700 ~/.loadenv
Put files ending with .env
into the ~/.loadenv/
directory containing environment variable definitions.
# ~/.loadenv/sample.env
SAMPLE_API_KEY=super_secret
Make sure the loadenv.sh
is loaded into your bash environment, then use it like this:
loadenv sample
loadenv
supports tab completion of all .env
files found in ~/.loadenv
.
loadenv list
: Shows all environment variables loaded through loadenv in the current session.loadenv clear
: Unsets all environment variables loaded through loadenv in the current session.
Use the loadenv list
command to see all variables loaded through loadenv:
loadenv list
Use the loadenv clear
command to unset all variables loaded through loadenv:
loadenv clear
Use the env
command to list all environment variables currently set (pipe it to sort
for better readability):
env | sort
- Tab completion for
.env
files in~/.loadenv/
- Keeps track of loaded variables for easy listing and clearing
- Prevents duplicate loading of variables
The current implementation may have problems with spaces in the filenames for .loadenv
files.
This project is licensed under the MIT License.