]> Sergey Matveev's repositories - zsh-autoenv.git/blobdiff - autoenv.zsh
Cleanup tests/varstash_export.t
[zsh-autoenv.git] / autoenv.zsh
index 24f4b04481ca7735a9ef1286fcecf36bacef3efb..2fb77ce966da17e50d20e7000216e59e307e6dcd 100644 (file)
@@ -41,10 +41,8 @@ autoenv_source_parent() {
 # Internal functions. {{{
 # Internal: stack of entered (and handled) directories. {{{
 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() {
@@ -60,13 +58,23 @@ _autoenv_stack_entered_add() {
   _autoenv_stack_entered_mtime[$env_file]=$(_autoenv_get_file_mtime $env_file)
 }
 
-_autoenv_get_file_mtime() {
-  if [[ -f $1 ]]; then
-    zstat +mtime $1
-  else
-    echo 0
-  fi
-}
+
+# zstat_mime helper, conditionally defined.
+# Load zstat module, but only its builtin `zstat`.
+if ! zmodload -F zsh/stat b:zstat 2>/dev/null; then
+  # If the module is not available, define a wrapper around `stat`, and use its
+  # terse output instead of format, which is not supported by busybox.
+  # Assume '+mtime' as $1.
+  _autoenv_get_file_mtime() {
+    setopt localoptions pipefail
+    stat -t $1 2>/dev/null | cut -f13 -d ' ' || echo 0
+  }
+else
+  _autoenv_get_file_mtime() {
+    zstat +mtime $1 2>/dev/null || echo 0
+  }
+fi
+
 
 # Remove an entry from the stack.
 _autoenv_stack_entered_remove() {
@@ -132,16 +140,6 @@ _autoenv_debug() {
 }
 # }}}
 
-# Load zstat module, but only its builtin `zstat`.
-if ! zmodload -F zsh/stat b:zstat 2>/dev/null; then
-  # If the module is not available, define a wrapper around `stat`, and use its
-  # terse output instead of format, which is not supported by busybox.
-  # Assume '+mtime' as $1.
-  zstat() {
-    stat -t $2 | cut -f13 -d ' '
-  }
-fi
-
 
 # Generate hash pair for a given file ($1).
 # A fixed hash value can be given as 2nd arg, but is used with tests only.
@@ -237,12 +235,11 @@ _autoenv_source() {
     # ${env_file:h}.
   fi
 
-  # Change to directory of env file, source it and cd back.
-  local new_dir=$PWD
+  # Source the env file.
   _autoenv_debug "== SOURCE: ${bold_color:-}$env_file${reset_color:-}\n      PWD: $PWD"
-  (( _autoenv_debug_indent++ ))
+  : $(( _autoenv_debug_indent++ ))
   source $env_file
-  (( _autoenv_debug_indent-- ))
+  : $(( _autoenv_debug_indent-- ))
   _autoenv_debug "== END SOURCE =="
 
   if [[ $autoenv_event == enter ]]; then
@@ -339,7 +336,7 @@ _autoenv_chpwd_handler() {
 
   _autoenv_chpwd_prev_dir=$PWD
 
-  (( _autoenv_debug_indent++ ))
+  : $(( _autoenv_debug_indent++ ))
 }
 # }}}