Skip to content

Commit c4de255

Browse files
andrew-christiansonAndrew Christianson
and
Andrew Christianson
authored
Use realpath of scripts to determine relative locations (#308)
Just using paths relative to ${BASH_SOURCE} to access `libexec` fails if the scripts are symlinked to a location, such as when installed with Homebrew, since the `libexec` directory is not linked into `brew --prefix`. Implement a simple version of `realpath` and run `${BASH_SOURCE}` through it. This gets the actual installation directory relative to which `libexec` is located. Co-authored-by: Andrew Christianson <[email protected]>
1 parent 633711a commit c4de255

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

bin/pyenv-virtualenv-prefix

+15-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,21 @@
66

77
set -e
88
[ -n "$PYENV_DEBUG" ] && set -x
9-
. "${BASH_SOURCE%/*}"/../libexec/pyenv-virtualenv-realpath
9+
if [ -L "${BASH_SOURCE}" ]; then
10+
READLINK=$(type -p greadlink readlink | head -1)
11+
if [ -z "$READLINK" ]; then
12+
echo "pyenv: cannot find readlink - are you missing GNU coreutils?" >&2
13+
exit 1
14+
fi
15+
resolve_link() {
16+
$READLINK -f "$1"
17+
}
18+
script_path=$(resolve_link ${BASH_SOURCE})
19+
else
20+
script_path=${BASH_SOURCE}
21+
fi
22+
23+
. ${script_path%/*}/../libexec/pyenv-virtualenv-realpath
1024

1125
if [ -z "$PYENV_ROOT" ]; then
1226
PYENV_ROOT="${HOME}/.pyenv"

bin/pyenv-virtualenvs

+15-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,21 @@
77

88
set -e
99
[ -n "$PYENV_DEBUG" ] && set -x
10-
. "${BASH_SOURCE%/*}"/../libexec/pyenv-virtualenv-realpath
10+
if [ -L "${BASH_SOURCE}" ]; then
11+
READLINK=$(type -p greadlink readlink | head -1)
12+
if [ -z "$READLINK" ]; then
13+
echo "pyenv: cannot find readlink - are you missing GNU coreutils?" >&2
14+
exit 1
15+
fi
16+
resolve_link() {
17+
$READLINK -f "$1"
18+
}
19+
script_path=$(resolve_link ${BASH_SOURCE})
20+
else
21+
script_path=${BASH_SOURCE}
22+
fi
23+
24+
. ${script_path%/*}/../libexec/pyenv-virtualenv-realpath
1125

1226
if [ -z "$PYENV_ROOT" ]; then
1327
PYENV_ROOT="${HOME}/.pyenv"

0 commit comments

Comments
 (0)