From a6c989866066635f3fd7ccca8a9288d5d8be9a05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Cabrera=20Dur=C3=A1n?= Date: Fri, 7 Dec 2018 17:28:20 -0600 Subject: [PATCH 1/3] feat(dotenv): autoload .env files --- lib/util/dotenv.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 lib/util/dotenv.sh diff --git a/lib/util/dotenv.sh b/lib/util/dotenv.sh new file mode 100644 index 0000000..91c1222 --- /dev/null +++ b/lib/util/dotenv.sh @@ -0,0 +1,10 @@ +dotenv () { + envfile="${1:-$(pwd)}/.env" + + if [[ -f "$envfile" ]] + then + export $(egrep -v '^#' "$envfile" | xargs) + fi +} + +dotenv From d27720955812255aa3d17f9bc46198698b3e04b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Cabrera=20Dur=C3=A1n?= Date: Mon, 10 Dec 2018 16:38:55 -0600 Subject: [PATCH 2/3] feat(dotenv): allow spaces on .env values --- lib/util/dotenv.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/util/dotenv.sh b/lib/util/dotenv.sh index 91c1222..1eedfe2 100644 --- a/lib/util/dotenv.sh +++ b/lib/util/dotenv.sh @@ -1,9 +1,15 @@ dotenv () { envfile="${1:-$(pwd)}/.env" + N='�' # CHR(160) if [[ -f "$envfile" ]] then - export $(egrep -v '^#' "$envfile" | xargs) + locals=( $(egrep -v '^#' "$envfile" | tr ' ' "$N" | xargs) ) + + for var in "${locals[@]}" + do + export "$(echo $var | tr "$N" ' ')" + done fi } From 3cc896dae7d4a1db597fcbe9d1e82f3e79ff2dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Cabrera=20Dur=C3=A1n?= Date: Tue, 11 Dec 2018 09:50:55 -0600 Subject: [PATCH 3/3] feat(dotenv): set IFS for handling spaces --- lib/util/dotenv.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/util/dotenv.sh b/lib/util/dotenv.sh index 1eedfe2..6951026 100644 --- a/lib/util/dotenv.sh +++ b/lib/util/dotenv.sh @@ -1,14 +1,14 @@ dotenv () { envfile="${1:-$(pwd)}/.env" - N='�' # CHR(160) if [[ -f "$envfile" ]] then - locals=( $(egrep -v '^#' "$envfile" | tr ' ' "$N" | xargs) ) + IFS=$'\n' locals=( $(egrep -v '^#' "$envfile") ) + IFS=$' \t\n' for var in "${locals[@]}" do - export "$(echo $var | tr "$N" ' ')" + export "$var" done fi }