.lib/sh/stubexec.sh

Tue, 02 May 2023 17:31:49 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Tue, 02 May 2023 17:31:49 -0500
changeset 1107
c6d7ac40bd3c
parent 1002
8284b9cac608
child 1110
e4edb1419e3f
permissions
-rw-r--r--

move stubs to own location

932
f87943eb16aa stubexec fixes
Meredith Howard <mhoward@roomag.org>
parents: 915
diff changeset
1 realpath() {
f87943eb16aa stubexec fixes
Meredith Howard <mhoward@roomag.org>
parents: 915
diff changeset
2 local dir="$(dirname -- "$1")"
f87943eb16aa stubexec fixes
Meredith Howard <mhoward@roomag.org>
parents: 915
diff changeset
3 local file="$(basename -- "$1")"
f87943eb16aa stubexec fixes
Meredith Howard <mhoward@roomag.org>
parents: 915
diff changeset
4 (cd "$dir" 2>/dev/null && printf '%s/%s\n' "$(pwd -P)" "$file")
f87943eb16aa stubexec fixes
Meredith Howard <mhoward@roomag.org>
parents: 915
diff changeset
5 }
f87943eb16aa stubexec fixes
Meredith Howard <mhoward@roomag.org>
parents: 915
diff changeset
6
958
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
7 shim_filter() {
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
8 local binpath=''
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
9 while read binpath; do
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
10 case "$binpath" in
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
11 */.plenv/shims/*)
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
12 plenv which $1 >/dev/null 2>&1 || continue
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
13 ;;
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
14 */.asdf/shims/*)
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
15 asdf which $1 >/dev/null 2>&1 || continue
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
16 ;;
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
17 esac
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
18 echo "$binpath"
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
19 done
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
20 }
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
21
1002
8284b9cac608 Add age limit reinstall check
Meredith Howard <mhoward@roomag.org>
parents: 995
diff changeset
22 age_check() {
8284b9cac608 Add age limit reinstall check
Meredith Howard <mhoward@roomag.org>
parents: 995
diff changeset
23 local subject=''
8284b9cac608 Add age limit reinstall check
Meredith Howard <mhoward@roomag.org>
parents: 995
diff changeset
24 read subject
8284b9cac608 Add age limit reinstall check
Meredith Howard <mhoward@roomag.org>
parents: 995
diff changeset
25 find "$subject" -mtime -${age_limit:-90} -print
8284b9cac608 Add age limit reinstall check
Meredith Howard <mhoward@roomag.org>
parents: 995
diff changeset
26 }
8284b9cac608 Add age limit reinstall check
Meredith Howard <mhoward@roomag.org>
parents: 995
diff changeset
27
957
ea852d545173 improve stubexec
Meredith Howard <mhoward@roomag.org>
parents: 932
diff changeset
28 realbin() {
960
4921edc4b518 fix stubexec
Meredith Howard <mhoward@roomag.org>
parents: 958
diff changeset
29 local bn="$(basename $1)"
4921edc4b518 fix stubexec
Meredith Howard <mhoward@roomag.org>
parents: 958
diff changeset
30 which -a "$bn" |
957
ea852d545173 improve stubexec
Meredith Howard <mhoward@roomag.org>
parents: 932
diff changeset
31 grep -v "$(realpath $1)" |
960
4921edc4b518 fix stubexec
Meredith Howard <mhoward@roomag.org>
parents: 958
diff changeset
32 shim_filter "$bn" |
957
ea852d545173 improve stubexec
Meredith Howard <mhoward@roomag.org>
parents: 932
diff changeset
33 head -n 1
ea852d545173 improve stubexec
Meredith Howard <mhoward@roomag.org>
parents: 932
diff changeset
34 }
ea852d545173 improve stubexec
Meredith Howard <mhoward@roomag.org>
parents: 932
diff changeset
35
915
55a1c83b3417 spin out stubexec
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
36 stubexec() {
1002
8284b9cac608 Add age limit reinstall check
Meredith Howard <mhoward@roomag.org>
parents: 995
diff changeset
37 local real_bin="$(realbin "$0" | age_check)"
915
55a1c83b3417 spin out stubexec
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
38 if [ -x "$real_bin" ]; then
995
ef237971026b fix arg passthrough
Meredith Howard <mhoward@roomag.org>
parents: 992
diff changeset
39 exec "$real_bin" "$@"
915
55a1c83b3417 spin out stubexec
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
40 fi
957
ea852d545173 improve stubexec
Meredith Howard <mhoward@roomag.org>
parents: 932
diff changeset
41 install_it
1002
8284b9cac608 Add age limit reinstall check
Meredith Howard <mhoward@roomag.org>
parents: 995
diff changeset
42 touch "$(realbin "$0")" # In case of no updates
995
ef237971026b fix arg passthrough
Meredith Howard <mhoward@roomag.org>
parents: 992
diff changeset
43 stubexec "$@"
915
55a1c83b3417 spin out stubexec
Meredith Howard <mhoward@roomag.org>
parents:
diff changeset
44 }
992
4e3e37ce84bc Switch stubexec to self-invoke
Meredith Howard <mhoward@roomag.org>
parents: 960
diff changeset
45
4e3e37ce84bc Switch stubexec to self-invoke
Meredith Howard <mhoward@roomag.org>
parents: 960
diff changeset
46 stubexec "$@"

mercurial