# This function can be mocked in tests
_autoenv_ask_for_yes() {
local answer
+
+ # Handle/catch Ctrl-C and return, instead of letting it potentially abort the
+ # shell setup process.
+ setopt localtraps
+ trap 'return 1' INT
+
read answer
if [[ $answer == "yes" ]]; then
return 0
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
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