]> Sergey Matveev's repositories - zsh-autoenv.git/blobdiff - autoenv.zsh
_autoenv_hash_pair: use sha1sum (C) instead of shasum (Perl) (#52)
[zsh-autoenv.git] / autoenv.zsh
index 12e058d463a34090cf94ac7c0392a6192a382bd0..5882f9f6564143d3b41976133455d7ce05073593 100644 (file)
@@ -16,7 +16,7 @@ if [[ -z $AUTOENV_AUTH_FILE ]]; then
     fi
     if [[ -f ~/.env_auth ]]; then
       echo "zsh-autoenv: using deprecated location for AUTOENV_AUTH_FILE." >&2
-      echo "Please move it: mv ~/.env_auth ${(D)AUTOENV_AUTH_FILE}." >&2
+      echo "Please move it: mv ~/.env_auth ${(D)AUTOENV_AUTH_FILE}" >&2
       AUTOENV_AUTH_FILE=~/.env_auth
     fi
   fi
@@ -179,7 +179,7 @@ _autoenv_hash_pair() {
       echo "Missing file argument for _autoenv_hash_pair!" >&2
       return 1
     fi
-    env_shasum=$(shasum $env_file | cut -d' ' -f1)
+    env_shasum=$(sha1sum $env_file | cut -d' ' -f1)
   fi
   echo ":${env_file}:${env_shasum}:1"
 }
@@ -194,6 +194,7 @@ _autoenv_authorized_env_file() {
 _autoenv_authorize() {
   local env_file=${1:A}
   _autoenv_deauthorize $env_file
+  [[ -d ${AUTOENV_AUTH_FILE:h} ]] || mkdir -p ${AUTOENV_AUTH_FILE:h}
   _autoenv_hash_pair $env_file >>| $AUTOENV_AUTH_FILE
 }
 
@@ -260,8 +261,12 @@ _autoenv_source() {
   local autoenv_to_dir=$PWD
 
   # Source varstash library once.
+  # XXX: pollutes environment with e.g. `stash`, and `autostash` will cause
+  # an overwritten `stash` function to be called!
   if [[ -z "$functions[(I)autostash]" ]]; then
-    source ${${funcsourcetrace[1]%:*}:h}/lib/varstash
+    if \grep -qE '\b(autostash|autounstash|stash)\b' $autoenv_env_file; then
+      source ${${funcsourcetrace[1]%:*}:h}/lib/varstash
+    fi
     # NOTE: Varstash uses $PWD as default for varstash_dir, we might set it to
     # ${autoenv_env_file:h}.
   fi
@@ -331,7 +336,9 @@ _autoenv_chpwd_handler() {
         fi
 
         # Unstash any autostashed stuff.
-        varstash_dir=$prev_dir autounstash
+        if [[ -n "$functions[(I)autostash]" ]]; then
+          varstash_dir=$prev_dir autounstash
+        fi
 
         _autoenv_stack_entered_remove $prev_file
       fi