From f31bb529dea3592390454790e0263b74d3a7a15a Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 21 Nov 2014 20:15:08 +0100 Subject: [PATCH] s/ENV_AUTHORIZATION_FILE/AUTOENV_ENV_FILENAME/ Ref: https://github.com/Tarrasch/zsh-autoenv/issues/6 --- autoenv.zsh | 13 ++++++------- tests/.zshenv | 2 +- tests/autoenv.t | 10 +++++----- tests/cwd.t | 4 ++-- tests/setup.sh | 4 ++-- tests/varstash.t | 4 ++-- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/autoenv.zsh b/autoenv.zsh index b7f5976..5be6c31 100644 --- a/autoenv.zsh +++ b/autoenv.zsh @@ -1,8 +1,7 @@ # Initially based on # https://github.com/joshuaclayton/dotfiles/blob/master/zsh_profile.d/autoenv.zsh -# TODO: move this to DOTENV_*?! -export ENV_AUTHORIZATION_FILE=$HOME/.env_auth +export AUTOENV_ENV_FILENAME=$HOME/.env_auth # Name of file to look for when entering directories. : ${DOTENV_FILE_ENTER:=.env} @@ -31,20 +30,20 @@ _dotenv_hash_pair() { _dotenv_authorized_env_file() { local env_file=$1 local pair=$(_dotenv_hash_pair $env_file) - test -f $ENV_AUTHORIZATION_FILE \ - && \grep -qF $pair $ENV_AUTHORIZATION_FILE + test -f $AUTOENV_ENV_FILENAME \ + && \grep -qF $pair $AUTOENV_ENV_FILENAME } _dotenv_authorize() { local env_file=$1 _dotenv_deauthorize $env_file - _dotenv_hash_pair $env_file >> $ENV_AUTHORIZATION_FILE + _dotenv_hash_pair $env_file >> $AUTOENV_ENV_FILENAME } _dotenv_deauthorize() { local env_file=$1 - if [[ -f $ENV_AUTHORIZATION_FILE ]]; then - echo $(\grep -vF $env_file $ENV_AUTHORIZATION_FILE) > $ENV_AUTHORIZATION_FILE + if [[ -f $AUTOENV_ENV_FILENAME ]]; then + echo $(\grep -vF $env_file $AUTOENV_ENV_FILENAME) > $AUTOENV_ENV_FILENAME fi } diff --git a/tests/.zshenv b/tests/.zshenv index 1c0a9d2..d70711b 100644 --- a/tests/.zshenv +++ b/tests/.zshenv @@ -1,4 +1,4 @@ test -f "$TESTDIR/.zcompdump" && rm "$TESTDIR/.zcompdump" source "$TESTDIR/../autoenv.plugin.zsh" -export ENV_AUTHORIZATION_FILE="$PWD/.env_auth" +export AUTOENV_ENV_FILENAME="$PWD/.env_auth" diff --git a/tests/autoenv.t b/tests/autoenv.t index 940050a..4750912 100644 --- a/tests/autoenv.t +++ b/tests/autoenv.t @@ -6,14 +6,14 @@ Lets set a simple .env action Manually create auth file - $ echo "$PWD/.env:$(echo echo ENTERED | shasum)" > $ENV_AUTHORIZATION_FILE + $ echo "$PWD/.env:$(echo echo ENTERED | shasum)" > $AUTOENV_ENV_FILENAME $ cd . ENTERED Now try to make it accept it $ unset _dotenv_stack_entered - $ rm $ENV_AUTHORIZATION_FILE + $ rm $AUTOENV_ENV_FILENAME $ _dotenv_read_answer() { echo 'y' } $ cd . Attempting to load unauthorized env file: /tmp/cramtests-??????/autoenv.t/.env (glob) @@ -40,8 +40,8 @@ Now lets see that it actually checks the shasum value ENTERED $ unset _dotenv_stack_entered - $ rm $ENV_AUTHORIZATION_FILE - $ echo "$PWD/.env:$(echo mischief | shasum)" > $ENV_AUTHORIZATION_FILE + $ rm $AUTOENV_ENV_FILENAME + $ echo "$PWD/.env:$(echo mischief | shasum)" > $AUTOENV_ENV_FILENAME $ cd . Attempting to load unauthorized env file: /tmp/cramtests-??????/autoenv.t/.env (glob) @@ -61,7 +61,7 @@ Now lets see that it actually checks the shasum value Now, will it take no for an answer? $ unset _dotenv_stack_entered - $ rm $ENV_AUTHORIZATION_FILE + $ rm $AUTOENV_ENV_FILENAME $ _dotenv_read_answer() { echo 'n' } $ cd . Attempting to load unauthorized env file: /tmp/cramtests-??????/autoenv.t/.env (glob) diff --git a/tests/cwd.t b/tests/cwd.t index 526ff63..99f77fe 100644 --- a/tests/cwd.t +++ b/tests/cwd.t @@ -12,8 +12,8 @@ Setup env actions / output. Manually create auth files. - $ echo "$PWD/$DOTENV_FILE_ENTER:$(echo $(<$DOTENV_FILE_ENTER) | shasum)" > $ENV_AUTHORIZATION_FILE - $ echo "$PWD/$DOTENV_FILE_LEAVE:$(echo $(<$DOTENV_FILE_LEAVE) | shasum)" >> $ENV_AUTHORIZATION_FILE + $ echo "$PWD/$DOTENV_FILE_ENTER:$(echo $(<$DOTENV_FILE_ENTER) | shasum)" > $AUTOENV_ENV_FILENAME + $ echo "$PWD/$DOTENV_FILE_LEAVE:$(echo $(<$DOTENV_FILE_LEAVE) | shasum)" >> $AUTOENV_ENV_FILENAME The actual tests. diff --git a/tests/setup.sh b/tests/setup.sh index efa99ab..b2f5aaf 100644 --- a/tests/setup.sh +++ b/tests/setup.sh @@ -1,6 +1,6 @@ -# Ensure we have our mocked out ENV_AUTHORIZATION_FILE +# Ensure we have our mocked out AUTOENV_ENV_FILENAME -[[ $ENV_AUTHORIZATION_FILE[0,4] == '/tmp' ]] || return 1 +[[ $AUTOENV_ENV_FILENAME[0,4] == '/tmp' ]] || return 1 # Inject timeout for `read` while running tests. _AUTOENV_TEST_READ_ARGS='-t 1' diff --git a/tests/varstash.t b/tests/varstash.t index 75a4077..bc49657 100644 --- a/tests/varstash.t +++ b/tests/varstash.t @@ -16,8 +16,8 @@ Setup test environment. Manually create auth file - $ echo "$PWD/$DOTENV_FILE_ENTER:$(echo $(<$DOTENV_FILE_ENTER) | shasum)" > $ENV_AUTHORIZATION_FILE - $ echo "$PWD/$DOTENV_FILE_LEAVE:$(echo $(<$DOTENV_FILE_LEAVE) | shasum)" >> $ENV_AUTHORIZATION_FILE + $ echo "$PWD/$DOTENV_FILE_ENTER:$(echo $(<$DOTENV_FILE_ENTER) | shasum)" > $AUTOENV_ENV_FILENAME + $ echo "$PWD/$DOTENV_FILE_LEAVE:$(echo $(<$DOTENV_FILE_LEAVE) | shasum)" >> $AUTOENV_ENV_FILENAME Set environment variable. -- 2.44.0