Skip to content

Commit

Permalink
Merge pull request #238 from tomtseng/tomtseng/leave-prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperupcall committed Jun 30, 2024
2 parents defad50 + 52df299 commit c3699a4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
27 changes: 17 additions & 10 deletions activate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -295,18 +295,25 @@ autoenv_leave() {
_files=$(
command -v chdir >/dev/null 2>&1 && chdir "${from_dir}" || builtin cd "${from_dir}"
_hadone=''
while [ "$PWD" != "" ] && [[ $to_dir != $PWD* ]]; do
_file="$PWD/${AUTOENV_ENV_LEAVE_FILENAME}"
if [ -f "${_file}" ]; then
if [ -z "${_hadone}" ]; then
printf %s "${_file}"
_hadone='1'
else
printf %s "
while [ "$PWD" != "" ] && [ "$PWD" != "/" ]; do
case $to_dir/ in
$PWD/*)
break
;;
*)
_file="$PWD/${AUTOENV_ENV_LEAVE_FILENAME}"
if [ -f "${_file}" ]; then
if [ -z "${_hadone}" ]; then
printf %s "${_file}"
_hadone='1'
else
printf %s "
${_file}"
fi
fi
fi
command -v chdir >/dev/null 2>&1 && chdir "$(pwd)/.." || builtin cd "$PWD/.."
command -v chdir >/dev/null 2>&1 && chdir "$(pwd)/.." || builtin cd "$PWD/.."
;;
esac
done
)

Expand Down
12 changes: 12 additions & 0 deletions tests/test_cd_env_leave.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# shellcheck shell=sh

. "${FUNCTIONS}"
. "${ACTIVATE_SH}"

# Prepare files/directories
mkdir -pv 'a/b' 'a/bz'
echo 'echo zulu' > 'a/b/.env.leave'

AUTOENV_ENABLE_LEAVE=1
cd 'a/b'
patterntest 'echo "Y" | cd ../../a/bz' 'zulu$'

0 comments on commit c3699a4

Please sign in to comment.