Skip to content

Commit

Permalink
autoenv_leave: Only match prefix on path boundaries
Browse files Browse the repository at this point in the history
Suppose we `cd` from `a/b` to `a/bz`.

Expected behavior: Invoke `a/b/.env.leave.

Actual behavior prior to this commit: No env-leave is invoked.

The issue is that we are naively checking for string prefixes in
`autoenv_leave` in order to determine whether one directory is an
ancestor of another. This commit makes the checking slightly less naive.
  • Loading branch information
tomtseng committed Jun 22, 2024
1 parent defad50 commit 0d284bd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion activate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ autoenv_leave() {
_files=$(
command -v chdir >/dev/null 2>&1 && chdir "${from_dir}" || builtin cd "${from_dir}"
_hadone=''
while [ "$PWD" != "" ] && [[ $to_dir != $PWD* ]]; do
while [ "$PWD" != "" ] && [ "$PWD" != "/" ] && [[ $to_dir/ != $PWD/* ]]; do
_file="$PWD/${AUTOENV_ENV_LEAVE_FILENAME}"
if [ -f "${_file}" ]; then
if [ -z "${_hadone}" ]; then
Expand Down

0 comments on commit 0d284bd

Please sign in to comment.