dustin
/
zdotdir
Archived
1
0
Fork 0

functions: dotenv: export variables from .env

Tools (such as VSCode) can read and use environment variables from a
file in the current working directory named `.env`.  Unfortunately,
these tools are not exactly compatible with shell syntax, as they do not
correctly process lines starting with `export`.

The `dotenv` function will read a `.env` file from the current working
directory and then export all of the variables it defines.  This allows
the `.env` file to define the variables without "exporting" them, making
them compatible with VSCode et al, but still allowing the same
environment variables to be set in the shell and its child processes.
master
Dustin 2020-02-08 14:23:18 -06:00
parent 04ce9e66e3
commit d9d559c327
1 changed files with 10 additions and 0 deletions

10
functions/dotenv Normal file
View File

@ -0,0 +1,10 @@
# vim: set ft=zsh sw=4 ts=4 sts=4 et :
function dotenv() {
if [ -f .env ]; then
. ./.env || return $?
eval $(awk -F= '{print "export",$1}' .env)
fi
}
dotenv