Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit

Permalink
Use empty CDPATH with cd in abs_dirname/expand_path
Browse files Browse the repository at this point in the history
While not recommended [1] `CDPATH` might be exported and would be used
for e.g. `cd test` instead of using `./test`.
E.g. Vim will make use of it (and therefore it needs to be exported, if
you do not want to configure it twice).

Fixes #104.

This supersedes #119: there is
no need to unset/change CDPATH globally.

1: https://bosker.wordpress.com/2012/02/12/bash-scripters-beware-of-the-cdpath/
  • Loading branch information
blueyed committed Apr 4, 2016
1 parent 0360811 commit 1f4c134
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions libexec/bats
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ abs_dirname() {
local path="$1"

while [ -n "$path" ]; do
cd "${path%/*}"
CDPATH= cd "${path%/*}"
local name="${path##*/}"
path="$(resolve_link "$name" || true)"
done

pwd
cd "$cwd"
CDPATH= cd "$cwd"
}

expand_path() {
{ cd "$(dirname "$1")" 2>/dev/null
{ CDPATH= cd "$(dirname "$1")" 2>/dev/null
local dirname="$PWD"
cd "$OLDPWD"
CDPATH= cd "$OLDPWD"
echo "$dirname/$(basename "$1")"
} || echo "$1"
}
Expand Down

0 comments on commit 1f4c134

Please sign in to comment.