Skip to content

Instantly share code, notes, and snippets.

@skunkworker
Created February 17, 2018 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skunkworker/70fbbb0f9a966c6e83085baaff70f53c to your computer and use it in GitHub Desktop.
Save skunkworker/70fbbb0f9a966c6e83085baaff70f53c to your computer and use it in GitHub Desktop.
fixed dotenv.zsh for loading and excluding comments.
#! /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
@skunkworker
Copy link
Author

This skips lines where a comment begins with a #

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment