Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoenv_leave: Only match prefix on path boundaries #238

Merged
merged 2 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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$'
Loading