Skip to content

Commit fbf45fd

Browse files
authored
feat(gnu-utils): Fix paths to GNU utilities on MacOS and *BSD Platforms (#3)
* feat(gnu-utils): Fix paths to GNU utilities on MacOS and *BSD Platforms When using non-GNU based OSs, you usually use Ports (homebrew, macports, or ports on BSD(s)), and the GNU tool variants have `g` prepended. Non-GNU versions are usually not usable because they lack some switches so prefer them whenever available. Signed-off-by: Bryan Hundven <[email protected]>
1 parent 3f573cd commit fbf45fd

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

bin/pyenv-users

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,41 @@ fi
7979
# and `venvs` are venv pathnames. Using parallel arrays since arrays-of-arrays
8080
# are a pain in bash. Keeping versions and venvs separate avoids needing awk.
8181
declare -a links versions venvs
82+
declare readlink realpath find
83+
84+
if [ -n "$(type -p greadlink)" ]; then
85+
readlink="$(type -p greadlink)"
86+
else
87+
readlink="readlink"
88+
fi
89+
90+
if [ -n "$(type -p grealpath)" ]; then
91+
realpath="$(type -p grealpath)"
92+
else
93+
realpath="realpath"
94+
fi
95+
96+
if [ -n "$(type -p gfind)" ]; then
97+
find="$(type -p gfind)"
98+
else
99+
find="find"
100+
fi
82101

83102
if [ -z "$PYENV_ROOT" ]; then
84103
PYENV_ROOT=$(pyenv root)
85104
fi
86105

87106
# Collect all symlinks named `python` that point into $PYENV_ROOT
88-
cmd="readlink -f '{}' | grep -q ${PYENV_ROOT}"
107+
cmd="${readlink} -f '{}' | grep -q ${PYENV_ROOT}"
89108
while IFS= read -r -d $'\0' file; do
90109
links+=("$file")
91-
done < <(find -H "$DIR" -name "python" -type l -exec sh -c "$cmd" \; -print0)
110+
done < <(${find} -H "$DIR" -name "python" -type l -exec sh -c "$cmd" \; -print0)
92111

93112
# Turn each link into a (version, venv) string pair
94113
regex="${PYENV_ROOT}/versions/(.+)/bin/(.+)"
95114
for link in "${links[@]}"; do
96-
linkpath=$(realpath -s "$link")
97-
target=$(readlink -f "$link")
115+
linkpath=$(${realpath} -s "$link")
116+
target=$(${readlink} -f "$link")
98117
[[ "$target" =~ $regex ]]
99118
version="${BASH_REMATCH[1]}"
100119
# Only capture links outside PYENV_ROOT or inside pyenv-virtualenv venvs

0 commit comments

Comments
 (0)