|
79 | 79 | # and `venvs` are venv pathnames. Using parallel arrays since arrays-of-arrays
|
80 | 80 | # are a pain in bash. Keeping versions and venvs separate avoids needing awk.
|
81 | 81 | 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 |
82 | 101 |
|
83 | 102 | if [ -z "$PYENV_ROOT" ]; then
|
84 | 103 | PYENV_ROOT=$(pyenv root)
|
85 | 104 | fi
|
86 | 105 |
|
87 | 106 | # 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}" |
89 | 108 | while IFS= read -r -d $'\0' file; do
|
90 | 109 | 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) |
92 | 111 |
|
93 | 112 | # Turn each link into a (version, venv) string pair
|
94 | 113 | regex="${PYENV_ROOT}/versions/(.+)/bin/(.+)"
|
95 | 114 | 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") |
98 | 117 | [[ "$target" =~ $regex ]]
|
99 | 118 | version="${BASH_REMATCH[1]}"
|
100 | 119 | # Only capture links outside PYENV_ROOT or inside pyenv-virtualenv venvs
|
|
0 commit comments