# https://github.com/joshuaclayton/dotfiles/blob/master/zsh_profile.d/autoenv.zsh
export AUTOENV_ENV_FILENAME=$HOME/.env_auth
+[ -e $AUTOENV_ENV_FILENAME ] || touch $AUTOENV_ENV_FILENAME
# Name of file to look for when entering directories.
: ${AUTOENV_FILE_ENTER:=.env}
# Internal functions. {{{
# Internal: stack of entered (and handled) directories. {{{
-typeset -a _autoenv_stack_entered
-typeset -A _autoenv_stack_entered_mtime
+typeset -g -a _autoenv_stack_entered
+_autoenv_stack_entered=()
+# -g: make it global, this is required when used with antigen.
+typeset -g -A _autoenv_stack_entered_mtime
+_autoenv_stack_entered_mtime=()
# Add an entry to the stack, and remember its mtime.
_autoenv_stack_entered_add() {
local env_file=$1
- _autoenv_debug "[stack] adding: $env_file" 2
-
# Remove any existing entry.
_autoenv_stack_entered_remove $env_file
+ _autoenv_debug "[stack] adding: $env_file" 2
+
# Append it to the stack, and remember its mtime.
_autoenv_stack_entered+=($env_file)
_autoenv_stack_entered_mtime[$env_file]=$(_autoenv_get_file_mtime $env_file)
return
fi
# Load zsh color support.
- if [[ -z $colors ]]; then
+ if [[ -z $color ]]; then
autoload colors
colors
fi
_autoenv_authorize() {
local env_file=${1:A}
_autoenv_deauthorize $env_file
- _autoenv_hash_pair $env_file >> $AUTOENV_ENV_FILENAME
+ _autoenv_hash_pair $env_file >>| $AUTOENV_ENV_FILENAME
}
# Deauthorize a given filename, by removing it from the auth file.
_autoenv_deauthorize() {
local env_file=${1:A}
if [[ -s $AUTOENV_ENV_FILENAME ]]; then
- echo "$(\grep -vF :${env_file}: $AUTOENV_ENV_FILENAME)" > $AUTOENV_ENV_FILENAME
+ echo "$(\grep -vF :${env_file}: $AUTOENV_ENV_FILENAME)" >| $AUTOENV_ENV_FILENAME
fi
}