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

Wrap sourcing in _dotenv_source: chdir and set _dotenv_cwd=$PWD

This commit is contained in:
Daniel Hahler 2014-11-15 16:09:37 +01:00
parent d114d0a0ea
commit a37b0bc3f5

View File

@ -82,6 +82,18 @@ _dotenv_check_authorized_env_file() {
return 0 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() { _dotenv_chpwd_handler() {
local env_file="$PWD/$DOTENV_FILE_ENTER" local env_file="$PWD/$DOTENV_FILE_ENTER"
@ -91,9 +103,7 @@ _dotenv_chpwd_handler() {
if ! [[ ${PWD}/ == ${prev_dir}/* ]]; then if ! [[ ${PWD}/ == ${prev_dir}/* ]]; then
local env_file_leave=$prev_dir/$DOTENV_FILE_LEAVE local env_file_leave=$prev_dir/$DOTENV_FILE_LEAVE
if _dotenv_check_authorized_env_file $env_file_leave; then if _dotenv_check_authorized_env_file $env_file_leave; then
_dotenv_event=leave _dotenv_source $env_file_leave leave
source $env_file_leave
unset _dotenv_event
fi fi
# Remove this entry from the stack. # Remove this entry from the stack.
_dotenv_stack_entered=(${_dotenv_stack_entered#$prev_dir}) _dotenv_stack_entered=(${_dotenv_stack_entered#$prev_dir})
@ -123,9 +133,7 @@ _dotenv_chpwd_handler() {
_dotenv_stack_entered+=(${env_file:A:h}) _dotenv_stack_entered+=(${env_file:A:h})
_dotenv_event=enter _dotenv_source $env_file enter
source $env_file
unset _dotenv_event
} }
autoload -U add-zsh-hook autoload -U add-zsh-hook