autoenv.zsh | 9 ++++++--- tests/_autoenv_stack.t | 6 ++++++ tests/recurse-upwards.t | 3 ++- diff --git a/autoenv.zsh b/autoenv.zsh index c2daa07cc2de3d23a0b79c5dd7be0a8e7b9bc976..9f8ae9021f4233204b5b0bee5021ddc529f0e93d 100644 --- a/autoenv.zsh +++ b/autoenv.zsh @@ -29,6 +29,9 @@ if [[ -n $parent_env_file ]] \ && _autoenv_check_authorized_env_file $parent_env_file; then local parent_env_dir=${parent_env_file:A:h} + + _autoenv_stack_entered_add $parent_env_file + _autoenv_source $parent_env_file enter $parent_env_dir fi } @@ -44,7 +47,7 @@ _autoenv_stack_entered_add() { local env_file=$1 # Remove any existing entry. - _autoenv_stack_entered[$_autoenv_stack_entered[(i)$1]]=() + _autoenv_stack_entered_remove $env_file # Append it to the stack, and remember its mtime. _autoenv_stack_entered+=($env_file) @@ -62,7 +65,7 @@ # Remove an entry from the stack. _autoenv_stack_entered_remove() { local env_file=$1 - _autoenv_stack_entered=(${_autoenv_stack_entered#$env_file}) + _autoenv_stack_entered[$_autoenv_stack_entered[(i)$env_file]]=() _autoenv_stack_entered_mtime[$env_file]= } @@ -218,7 +221,7 @@ local env_file_leave=$prev_dir/$AUTOENV_FILE_LEAVE if _autoenv_check_authorized_env_file $env_file_leave; then _autoenv_source $env_file_leave leave $prev_dir fi - _autoenv_stack_entered_remove $prev_dir + _autoenv_stack_entered_remove $prev_file fi done fi diff --git a/tests/_autoenv_stack.t b/tests/_autoenv_stack.t index df1e0f946e6fdf62e1428d57248e1c2a0cd530c4..6f659c693462cee4f052bd27722e84f5c1466f66 100644 --- a/tests/_autoenv_stack.t +++ b/tests/_autoenv_stack.t @@ -50,3 +50,9 @@ $ _autoenv_stack_entered_contains non-existing $ _autoenv_stack_entered_contains not-added [1] +Test removing. + + $ _autoenv_stack_entered_remove sub + $ echo ${_autoenv_stack_entered} + sub/sub2 non-existing sub/file + diff --git a/tests/recurse-upwards.t b/tests/recurse-upwards.t index 6a4930f9a88ab12b18e5b5ca20bfed1ab5fa55d0..8d94bf349d6b0072742b97a7e05f312aafacee8c 100644 --- a/tests/recurse-upwards.t +++ b/tests/recurse-upwards.t @@ -98,10 +98,11 @@ done_sub done_sub2 Go to root. +This should not trigger the enter event, because it was handled via +autoenv_source_parent already. $ cd ../.. LEFT_sub: PWD:sub from:sub2 to:recurse-upwards.t - ENTERED_root: PWD:recurse-upwards.t from:sub2 to:recurse-upwards.t Changing the root .env should trigger re-authentication via autoenv_source_parent.