Created
February 17, 2018 21:17
-
-
Save skunkworker/70fbbb0f9a966c6e83085baaff70f53c to your computer and use it in GitHub Desktop.
fixed dotenv.zsh for loading and excluding comments.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/zsh | |
function dotenv () { | |
regex="DOT_ENV\=(\w+)" | |
if [[ $1 =~ $regex ]]; then | |
env="${match[1]}" | |
file_name=".env.${env}" | |
if [[ -f $file_name ]]; then | |
source_env $file_name | |
return | |
fi | |
fi | |
file_name=".env" | |
source_env $file_name | |
} | |
function source_env() { | |
source_specific_env ".env.clean" | |
source_specific_env $1 | |
} | |
function source_specific_env() { | |
if [[ -f $1 ]]; then | |
export $(cat ${1} | grep -v "^#" | xargs) | |
fi | |
} | |
autoload -Uz add-zsh-hook | |
add-zsh-hook preexec dotenv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This skips lines where a comment begins with a
#