Archived
1
0
This repository has been archived on 2023-11-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
zdotdir/functions/dotenv
Dustin C. Hatch d9d559c327 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.
2020-02-08 14:23:18 -06:00

11 lines
183 B
Bash

# 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