.lib/sh/stubexec.sh

changeset 958
b883fb5c4792
parent 957
ea852d545173
child 960
4921edc4b518
equal deleted inserted replaced
957:ea852d545173 958:b883fb5c4792
2 local dir="$(dirname -- "$1")" 2 local dir="$(dirname -- "$1")"
3 local file="$(basename -- "$1")" 3 local file="$(basename -- "$1")"
4 (cd "$dir" 2>/dev/null && printf '%s/%s\n' "$(pwd -P)" "$file") 4 (cd "$dir" 2>/dev/null && printf '%s/%s\n' "$(pwd -P)" "$file")
5 } 5 }
6 6
7 shim_filter() {
8 local binpath=''
9 while read binpath; do
10 case "$binpath" in
11 */.plenv/shims/*)
12 plenv which $1 >/dev/null 2>&1 || continue
13 ;;
14 */.asdf/shims/*)
15 asdf which $1 >/dev/null 2>&1 || continue
16 ;;
17 esac
18 echo "$binpath"
19 done
20 }
21
7 realbin() { 22 realbin() {
8 which -a $(basename $1) | 23 which -a $(basename $1) |
9 grep -v "$(realpath $1)" | 24 grep -v "$(realpath $1)" |
25 shim_filter |
10 head -n 1 26 head -n 1
11 } 27 }
12 28
13 stubexec() { 29 stubexec() {
14 local real_bin="$(realbin "$0")" 30 local real_bin="$(realbin "$0")"

mercurial