]> Sergey Matveev's repositories - zsh-autoenv.git/commitdiff
Merge pull request #36 from blueyed/fix-api-vars-scope
authorDaniel Hahler <github@thequod.de>
Sat, 10 Oct 2015 20:35:41 +0000 (22:35 +0200)
committerDaniel Hahler <github@thequod.de>
Sat, 10 Oct 2015 20:35:41 +0000 (22:35 +0200)
Cleanup API/vars for enter/leave events

1  2 
autoenv.zsh

diff --combined autoenv.zsh
index 96598345c74c338f943448c1fef0dfc727972ca1,e448dcefa381990200574fdb1df929259f24deba..f7e4f983915b419113e1762d1401e75a98a6daaf
@@@ -48,9 -48,7 +48,9 @@@ f
  # This is useful if you want to use a base .autoenv.zsh file for a directory
  # subtree.
  autoenv_source_parent() {
 -  local parent_env_file=$(_autoenv_get_file_upwards ${autoenv_env_file:h})
 +  local look_until=${1:-/}
 +  local parent_env_file=$(_autoenv_get_file_upwards \
 +    ${autoenv_env_file:h} ${AUTOENV_FILE_ENTER} $look_until)
  
    if [[ -n $parent_env_file ]] \
      && _autoenv_check_authorized_env_file $parent_env_file; then
@@@ -247,45 -245,34 +247,35 @@@ _autoenv_check_authorized_env_file() 
  }
  
  _autoenv_source() {
-   local env_file=$1
-   autoenv_event=$2
-   local _autoenv_envfile_dir=${3:-${1:A:h}}
-   autoenv_from_dir=$OLDPWD
-   autoenv_to_dir=$PWD
-   autoenv_env_file=$env_file
+   # Public API for the .autoenv.zsh script.
+   local autoenv_env_file=$1
+   local autoenv_event=$2
+   local autoenv_from_dir=$OLDPWD
+   local autoenv_to_dir=$PWD
  
    # Source varstash library once.
    if [[ -z "$functions[(I)autostash]" ]]; then
      source ${${funcsourcetrace[1]%:*}:h}/lib/varstash
      # NOTE: Varstash uses $PWD as default for varstash_dir, we might set it to
-     # ${env_file:h}.
+     # ${autoenv_env_file:h}.
    fi
  
    # Source the env file.
-   _autoenv_debug "== SOURCE: ${bold_color:-}$env_file${reset_color:-}\n      PWD: $PWD"
+   _autoenv_debug "== SOURCE: ${bold_color:-}$autoenv_env_file${reset_color:-}\n      PWD: $PWD"
    : $(( _autoenv_debug_indent++ ))
-   source $env_file
+   source $autoenv_env_file
    : $(( _autoenv_debug_indent-- ))
    _autoenv_debug "== END SOURCE =="
  
    if [[ $autoenv_event == enter ]]; then
-     _autoenv_stack_entered_add $env_file
-   fi
-   # Unset vars set for enter/leave scripts.
-   # This should not get done for recursion (via autoenv_source_parent),
-   # and can be useful to have in general after autoenv was used.
-   # unset autoenv_event autoenv_from_dir autoenv_to_dir autoenv_env_file
-   if [[ $autoenv_event == leave ]]; then
-     unset autoenv_env_file
+     _autoenv_stack_entered_add $autoenv_env_file
    fi
  }
  
  _autoenv_get_file_upwards() {
    local look_from=${1:-$PWD}
    local look_for=${2:-$AUTOENV_FILE_ENTER}
 +  local look_until=${${3:-/}:A}
  
    # Manually look in parent dirs. An extended Zsh glob should use Y1 for
    # performance reasons, which is only available in zsh-5.0.5-146-g9381bb6.
        break
      fi
  
 +    if [[ $parent_dir == $look_until ]]; then
 +      break
 +    fi
      last=$parent_dir
      parent_dir="${parent_dir}/.."
    done