View all files | ||||
Load environment variables such as API tokens or other sensitive settings into your current bash environment on demand, without having them permanently set in your shell.
The motivation for this approach is to avoid having sensitive tokens written to files in repositories, even if they do not get committed. Simply having sensitive data exist as files in your workspace poses security risks, as modern coding tools and IDEs rarely respect .gitignore files and will happily read everything they can get their hands on - basically everything that is in the workspace folder or below.
This approach mitigates this problem by storing sensitive environment files in a hidden folder (~/.loadenv/) in the home directory. While this is not a perfect security solution, it provides an acceptable compromise for many use cases by keeping sensitive data out of project workspaces entirely.
Add the following to your .bashrc or .bash_profile to load the loadenv functionality:
Create a .loadenv directory in your home directory and restrict access to your user only (recommended for security):
Place files ending with .env in the ~/.loadenv/ directory containing environment variable definitions.
Once loadenv.sh is loaded into your bash environment, use it as follows:
Use loadenv list to see all variables currently loaded through loadenv:
Use loadenv clear to unset all variables loaded through loadenv:
loadenv supports tab completion for all .env files found in ~/.loadenv/, as well as internal commands.
Use the env command to list all currently set environment variables (pipe to sort for better readability):
This project is licensed under the MIT License.