]> Sergey Matveev's repositories - zsh-autoenv.git/commitdiff
Merge pull request #12 from Tarrasch/autounstash-on-leave
authorDaniel Hahler <github@thequod.de>
Thu, 4 Dec 2014 12:31:56 +0000 (13:31 +0100)
committerDaniel Hahler <github@thequod.de>
Thu, 4 Dec 2014 12:31:56 +0000 (13:31 +0100)
Call `autounstash` automatically/always when leaving a directory

1  2 
autoenv.zsh

diff --combined autoenv.zsh
index b8a8f056170dcbf99d0b5581245fb8cface1e031,f8ca079f6de2aad2ba83a97c5938d0cd44b3832b..f87f350ba99bed31f9add25f27b4e8529e3af7a0
@@@ -122,21 -122,15 +122,21 @@@ _autoenv_debug() 
  zmodload -F zsh/stat b:zstat
  
  
 +# Generate hash pair for a given file ($1).
 +# A fixed hash value can be given as 2nd arg, but is used with tests only.
  _autoenv_hash_pair() {
    local env_file=${1:A}
    local env_shasum
    if [[ -n $2 ]]; then
      env_shasum=$2
    else
 +    if ! [[ -e $env_file ]]; then
 +      echo "Missing file argument for _autoenv_hash_pair!" >&2
 +      return 1
 +    fi
      env_shasum=$(shasum $env_file | cut -d' ' -f1)
    fi
 -  echo "$env_file:$env_shasum:1"
 +  echo ":${env_file}:${env_shasum}:1"
  }
  
  _autoenv_authorized_env_file() {
  }
  
  _autoenv_authorize() {
 -  local env_file=$1
 +  local env_file=${1:A}
    _autoenv_deauthorize $env_file
    _autoenv_hash_pair $env_file >> $AUTOENV_ENV_FILENAME
  }
  
 +# Deauthorize a given filename, by removing it from the auth file.
 +# This uses `test -s` to only handle non-empty files, and a subshell to
 +# allow for writing to the same file again.
  _autoenv_deauthorize() {
 -  local env_file=$1
 -  if [[ -f $AUTOENV_ENV_FILENAME ]]; then
 -    echo $(\grep -vF $env_file $AUTOENV_ENV_FILENAME) > $AUTOENV_ENV_FILENAME
 +  local env_file=${1:A}
 +  if [[ -s $AUTOENV_ENV_FILENAME ]]; then
 +    echo "$(\grep -vF :${env_file}: $AUTOENV_ENV_FILENAME)" > $AUTOENV_ENV_FILENAME
    fi
  }
  
@@@ -275,6 -266,10 +275,10 @@@ _autoenv_chpwd_handler() 
          if _autoenv_check_authorized_env_file $env_file_leave; then
            _autoenv_source $env_file_leave leave $prev_dir
          fi
+         # Unstash any autostash'd stuff.
+         varstash_dir=$prev_dir autounstash
          _autoenv_stack_entered_remove $prev_file
        fi
      done