mirror of
https://github.com/Tarrasch/zsh-autoenv.git
synced 2024-11-26 00:40:59 +02:00
s/ENV_AUTHORIZATION_FILE/AUTOENV_ENV_FILENAME/
Ref: https://github.com/Tarrasch/zsh-autoenv/issues/6
This commit is contained in:
parent
d9529636b0
commit
f31bb529de
13
autoenv.zsh
13
autoenv.zsh
@ -1,8 +1,7 @@
|
|||||||
# Initially based on
|
# Initially based on
|
||||||
# https://github.com/joshuaclayton/dotfiles/blob/master/zsh_profile.d/autoenv.zsh
|
# https://github.com/joshuaclayton/dotfiles/blob/master/zsh_profile.d/autoenv.zsh
|
||||||
|
|
||||||
# TODO: move this to DOTENV_*?!
|
export AUTOENV_ENV_FILENAME=$HOME/.env_auth
|
||||||
export ENV_AUTHORIZATION_FILE=$HOME/.env_auth
|
|
||||||
|
|
||||||
# Name of file to look for when entering directories.
|
# Name of file to look for when entering directories.
|
||||||
: ${DOTENV_FILE_ENTER:=.env}
|
: ${DOTENV_FILE_ENTER:=.env}
|
||||||
@ -31,20 +30,20 @@ _dotenv_hash_pair() {
|
|||||||
_dotenv_authorized_env_file() {
|
_dotenv_authorized_env_file() {
|
||||||
local env_file=$1
|
local env_file=$1
|
||||||
local pair=$(_dotenv_hash_pair $env_file)
|
local pair=$(_dotenv_hash_pair $env_file)
|
||||||
test -f $ENV_AUTHORIZATION_FILE \
|
test -f $AUTOENV_ENV_FILENAME \
|
||||||
&& \grep -qF $pair $ENV_AUTHORIZATION_FILE
|
&& \grep -qF $pair $AUTOENV_ENV_FILENAME
|
||||||
}
|
}
|
||||||
|
|
||||||
_dotenv_authorize() {
|
_dotenv_authorize() {
|
||||||
local env_file=$1
|
local env_file=$1
|
||||||
_dotenv_deauthorize $env_file
|
_dotenv_deauthorize $env_file
|
||||||
_dotenv_hash_pair $env_file >> $ENV_AUTHORIZATION_FILE
|
_dotenv_hash_pair $env_file >> $AUTOENV_ENV_FILENAME
|
||||||
}
|
}
|
||||||
|
|
||||||
_dotenv_deauthorize() {
|
_dotenv_deauthorize() {
|
||||||
local env_file=$1
|
local env_file=$1
|
||||||
if [[ -f $ENV_AUTHORIZATION_FILE ]]; then
|
if [[ -f $AUTOENV_ENV_FILENAME ]]; then
|
||||||
echo $(\grep -vF $env_file $ENV_AUTHORIZATION_FILE) > $ENV_AUTHORIZATION_FILE
|
echo $(\grep -vF $env_file $AUTOENV_ENV_FILENAME) > $AUTOENV_ENV_FILENAME
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
test -f "$TESTDIR/.zcompdump" && rm "$TESTDIR/.zcompdump"
|
test -f "$TESTDIR/.zcompdump" && rm "$TESTDIR/.zcompdump"
|
||||||
|
|
||||||
source "$TESTDIR/../autoenv.plugin.zsh"
|
source "$TESTDIR/../autoenv.plugin.zsh"
|
||||||
export ENV_AUTHORIZATION_FILE="$PWD/.env_auth"
|
export AUTOENV_ENV_FILENAME="$PWD/.env_auth"
|
||||||
|
@ -6,14 +6,14 @@ Lets set a simple .env action
|
|||||||
|
|
||||||
Manually create auth file
|
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 .
|
$ cd .
|
||||||
ENTERED
|
ENTERED
|
||||||
|
|
||||||
Now try to make it accept it
|
Now try to make it accept it
|
||||||
|
|
||||||
$ unset _dotenv_stack_entered
|
$ unset _dotenv_stack_entered
|
||||||
$ rm $ENV_AUTHORIZATION_FILE
|
$ rm $AUTOENV_ENV_FILENAME
|
||||||
$ _dotenv_read_answer() { echo 'y' }
|
$ _dotenv_read_answer() { echo 'y' }
|
||||||
$ cd .
|
$ cd .
|
||||||
Attempting to load unauthorized env file: /tmp/cramtests-??????/autoenv.t/.env (glob)
|
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
|
ENTERED
|
||||||
|
|
||||||
$ unset _dotenv_stack_entered
|
$ unset _dotenv_stack_entered
|
||||||
$ rm $ENV_AUTHORIZATION_FILE
|
$ rm $AUTOENV_ENV_FILENAME
|
||||||
$ echo "$PWD/.env:$(echo mischief | shasum)" > $ENV_AUTHORIZATION_FILE
|
$ echo "$PWD/.env:$(echo mischief | shasum)" > $AUTOENV_ENV_FILENAME
|
||||||
$ cd .
|
$ cd .
|
||||||
Attempting to load unauthorized env file: /tmp/cramtests-??????/autoenv.t/.env (glob)
|
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?
|
Now, will it take no for an answer?
|
||||||
|
|
||||||
$ unset _dotenv_stack_entered
|
$ unset _dotenv_stack_entered
|
||||||
$ rm $ENV_AUTHORIZATION_FILE
|
$ rm $AUTOENV_ENV_FILENAME
|
||||||
$ _dotenv_read_answer() { echo 'n' }
|
$ _dotenv_read_answer() { echo 'n' }
|
||||||
$ cd .
|
$ cd .
|
||||||
Attempting to load unauthorized env file: /tmp/cramtests-??????/autoenv.t/.env (glob)
|
Attempting to load unauthorized env file: /tmp/cramtests-??????/autoenv.t/.env (glob)
|
||||||
|
@ -12,8 +12,8 @@ Setup env actions / output.
|
|||||||
|
|
||||||
Manually create auth files.
|
Manually create auth files.
|
||||||
|
|
||||||
$ echo "$PWD/$DOTENV_FILE_ENTER:$(echo $(<$DOTENV_FILE_ENTER) | 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)" >> $ENV_AUTHORIZATION_FILE
|
$ echo "$PWD/$DOTENV_FILE_LEAVE:$(echo $(<$DOTENV_FILE_LEAVE) | shasum)" >> $AUTOENV_ENV_FILENAME
|
||||||
|
|
||||||
The actual tests.
|
The actual tests.
|
||||||
|
|
||||||
|
@ -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.
|
# Inject timeout for `read` while running tests.
|
||||||
_AUTOENV_TEST_READ_ARGS='-t 1'
|
_AUTOENV_TEST_READ_ARGS='-t 1'
|
||||||
|
@ -16,8 +16,8 @@ Setup test environment.
|
|||||||
|
|
||||||
Manually create auth file
|
Manually create auth file
|
||||||
|
|
||||||
$ echo "$PWD/$DOTENV_FILE_ENTER:$(echo $(<$DOTENV_FILE_ENTER) | 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)" >> $ENV_AUTHORIZATION_FILE
|
$ echo "$PWD/$DOTENV_FILE_LEAVE:$(echo $(<$DOTENV_FILE_LEAVE) | shasum)" >> $AUTOENV_ENV_FILENAME
|
||||||
|
|
||||||
Set environment variable.
|
Set environment variable.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user