1
0
mirror of https://github.com/Tarrasch/zsh-autoenv.git synced 2024-12-22 19:00:15 +02:00

s/ENV_AUTHORIZATION_FILE/AUTOENV_ENV_FILENAME/

Ref: https://github.com/Tarrasch/zsh-autoenv/issues/6
This commit is contained in:
Daniel Hahler 2014-11-21 20:15:08 +01:00
parent d9529636b0
commit f31bb529de
6 changed files with 18 additions and 19 deletions

View File

@ -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
}

View File

@ -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"

View File

@ -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)

View File

@ -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.

View File

@ -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'

View File

@ -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.