mirror of
https://github.com/Tarrasch/zsh-autoenv.git
synced 2024-11-22 07:20:59 +02:00
Wrap sourcing in _dotenv_source: chdir and set _dotenv_cwd=$PWD
This commit is contained in:
parent
d114d0a0ea
commit
a37b0bc3f5
20
autoenv.zsh
20
autoenv.zsh
@ -82,6 +82,18 @@ _dotenv_check_authorized_env_file() {
|
||||
return 0
|
||||
}
|
||||
|
||||
_dotenv_source() {
|
||||
local env_file=$1
|
||||
_dotenv_event=$2
|
||||
_dotenv_cwd=$PWD
|
||||
|
||||
cd -q ${env_file:h}
|
||||
source $env_file
|
||||
cd -q -
|
||||
|
||||
unset _dotenv_event _dotenv_cwd
|
||||
}
|
||||
|
||||
_dotenv_chpwd_handler() {
|
||||
local env_file="$PWD/$DOTENV_FILE_ENTER"
|
||||
|
||||
@ -91,9 +103,7 @@ _dotenv_chpwd_handler() {
|
||||
if ! [[ ${PWD}/ == ${prev_dir}/* ]]; then
|
||||
local env_file_leave=$prev_dir/$DOTENV_FILE_LEAVE
|
||||
if _dotenv_check_authorized_env_file $env_file_leave; then
|
||||
_dotenv_event=leave
|
||||
source $env_file_leave
|
||||
unset _dotenv_event
|
||||
_dotenv_source $env_file_leave leave
|
||||
fi
|
||||
# Remove this entry from the stack.
|
||||
_dotenv_stack_entered=(${_dotenv_stack_entered#$prev_dir})
|
||||
@ -123,9 +133,7 @@ _dotenv_chpwd_handler() {
|
||||
|
||||
_dotenv_stack_entered+=(${env_file:A:h})
|
||||
|
||||
_dotenv_event=enter
|
||||
source $env_file
|
||||
unset _dotenv_event
|
||||
_dotenv_source $env_file enter
|
||||
}
|
||||
|
||||
autoload -U add-zsh-hook
|
||||
|
Loading…
Reference in New Issue
Block a user