2 # https://github.com/joshuaclayton/dotfiles/blob/master/zsh_profile.d/autoenv.zsh
4 export ENV_AUTHORIZATION_FILE=$HOME/.env_auth
8 env_shasum=$(shasum $env_file | cut -d' ' -f1)
9 echo "$env_file:$env_shasum"
12 _dotenv_authorized_env_file() {
14 local pair=$(_dotenv_hash_pair $env_file)
15 touch $ENV_AUTHORIZATION_FILE
16 \grep -Gq $pair $ENV_AUTHORIZATION_FILE
21 _dotenv_deauthorize $env_file
22 _dotenv_hash_pair $env_file >> $ENV_AUTHORIZATION_FILE
25 _dotenv_deauthorize() {
27 echo $(\grep -Gv $env_file $ENV_AUTHORIZATION_FILE) > $ENV_AUTHORIZATION_FILE
30 _dotenv_print_unauthorized_message() {
31 echo "Attempting to load unauthorized env: $1"
33 echo "**********************************************"
37 echo "**********************************************"
39 echo "Would you like to authorize it? (y/n)"
42 # This function can be mocked in tests
43 _dotenv_read_answer() {
47 _dotenv_source_env() {
48 local env_file="$PWD/.env"
52 if _dotenv_authorized_env_file $env_file
58 _dotenv_print_unauthorized_message $env_file
62 if [[ $answer == 'y' ]]
64 _dotenv_authorize $env_file
70 chpwd_functions=($chpwd_functions _dotenv_source_env)