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
parent
04ce9e66e3
commit
d9d559c327
|
@ -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
|
Reference in New Issue