.lib/sh/stubexec.sh

Wed, 25 Sep 2024 15:03:13 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Wed, 25 Sep 2024 15:03:13 -0500
changeset 1179
b0a0ba3240b5
parent 1119
84cd2286f0bf
permissions
-rw-r--r--

No LSP autostart when read-only

I think nvim actually threw out 'view' argc detection, I just use -R and alias
view to it.

1115
15ca9da8cd59 use distinct db for update checks
Meredith Howard <mhoward@roomag.org>
parents: 1114
diff changeset
1 cache="${XDG_CACHE_HOME:-$HOME/.cache}/stubexec"
15ca9da8cd59 use distinct db for update checks
Meredith Howard <mhoward@roomag.org>
parents: 1114
diff changeset
2
15ca9da8cd59 use distinct db for update checks
Meredith Howard <mhoward@roomag.org>
parents: 1114
diff changeset
3 stubexec() {
1119
84cd2286f0bf Yeah, nix isn't for me yet.
Meredith Howard <mhoward@roomag.org>
parents: 1115
diff changeset
4 mkdir -p "$cache"
84cd2286f0bf Yeah, nix isn't for me yet.
Meredith Howard <mhoward@roomag.org>
parents: 1115
diff changeset
5
1115
15ca9da8cd59 use distinct db for update checks
Meredith Howard <mhoward@roomag.org>
parents: 1114
diff changeset
6 local real_bin="$(realbin "$0")"
15ca9da8cd59 use distinct db for update checks
Meredith Howard <mhoward@roomag.org>
parents: 1114
diff changeset
7 if [ ! -x "$real_bin" ] || age_check $0; then
1119
84cd2286f0bf Yeah, nix isn't for me yet.
Meredith Howard <mhoward@roomag.org>
parents: 1115
diff changeset
8 install_it
1115
15ca9da8cd59 use distinct db for update checks
Meredith Howard <mhoward@roomag.org>
parents: 1114
diff changeset
9 touch_checktime "$0"
15ca9da8cd59 use distinct db for update checks
Meredith Howard <mhoward@roomag.org>
parents: 1114
diff changeset
10 stubexec "$@"
15ca9da8cd59 use distinct db for update checks
Meredith Howard <mhoward@roomag.org>
parents: 1114
diff changeset
11 fi
15ca9da8cd59 use distinct db for update checks
Meredith Howard <mhoward@roomag.org>
parents: 1114
diff changeset
12 exec "$real_bin" "$@"
15ca9da8cd59 use distinct db for update checks
Meredith Howard <mhoward@roomag.org>
parents: 1114
diff changeset
13 }
15ca9da8cd59 use distinct db for update checks
Meredith Howard <mhoward@roomag.org>
parents: 1114
diff changeset
14
15ca9da8cd59 use distinct db for update checks
Meredith Howard <mhoward@roomag.org>
parents: 1114
diff changeset
15 touch_checktime() {
1119
84cd2286f0bf Yeah, nix isn't for me yet.
Meredith Howard <mhoward@roomag.org>
parents: 1115
diff changeset
16 kv "$cache/db" touch "$(basename $1)"
1115
15ca9da8cd59 use distinct db for update checks
Meredith Howard <mhoward@roomag.org>
parents: 1114
diff changeset
17 }
15ca9da8cd59 use distinct db for update checks
Meredith Howard <mhoward@roomag.org>
parents: 1114
diff changeset
18
15ca9da8cd59 use distinct db for update checks
Meredith Howard <mhoward@roomag.org>
parents: 1114
diff changeset
19 age_check() {
1119
84cd2286f0bf Yeah, nix isn't for me yet.
Meredith Howard <mhoward@roomag.org>
parents: 1115
diff changeset
20 kv "$cache/db" age_days_gt "$(basename $1)" "${age_limit:-90}"
1115
15ca9da8cd59 use distinct db for update checks
Meredith Howard <mhoward@roomag.org>
parents: 1114
diff changeset
21 }
15ca9da8cd59 use distinct db for update checks
Meredith Howard <mhoward@roomag.org>
parents: 1114
diff changeset
22
932
f87943eb16aa stubexec fixes
Meredith Howard <mhoward@roomag.org>
parents: 915
diff changeset
23 realpath() {
f87943eb16aa stubexec fixes
Meredith Howard <mhoward@roomag.org>
parents: 915
diff changeset
24 local dir="$(dirname -- "$1")"
f87943eb16aa stubexec fixes
Meredith Howard <mhoward@roomag.org>
parents: 915
diff changeset
25 local file="$(basename -- "$1")"
f87943eb16aa stubexec fixes
Meredith Howard <mhoward@roomag.org>
parents: 915
diff changeset
26 (cd "$dir" 2>/dev/null && printf '%s/%s\n' "$(pwd -P)" "$file")
f87943eb16aa stubexec fixes
Meredith Howard <mhoward@roomag.org>
parents: 915
diff changeset
27 }
f87943eb16aa stubexec fixes
Meredith Howard <mhoward@roomag.org>
parents: 915
diff changeset
28
958
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
29 shim_filter() {
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
30 local binpath=''
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
31 while read binpath; do
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
32 case "$binpath" in
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
33 */.plenv/shims/*)
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
34 plenv which $1 >/dev/null 2>&1 || continue
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
35 ;;
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
36 */.asdf/shims/*)
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
37 asdf which $1 >/dev/null 2>&1 || continue
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
38 ;;
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
39 esac
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
40 echo "$binpath"
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
41 done
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
42 }
b883fb5c4792 filter out shims that wont work
Meredith Howard <mhoward@roomag.org>
parents: 957
diff changeset
43
957
ea852d545173 improve stubexec
Meredith Howard <mhoward@roomag.org>
parents: 932
diff changeset
44 realbin() {
960
4921edc4b518 fix stubexec
Meredith Howard <mhoward@roomag.org>
parents: 958
diff changeset
45 local bn="$(basename $1)"
4921edc4b518 fix stubexec
Meredith Howard <mhoward@roomag.org>
parents: 958
diff changeset
46 which -a "$bn" |
957
ea852d545173 improve stubexec
Meredith Howard <mhoward@roomag.org>
parents: 932
diff changeset
47 grep -v "$(realpath $1)" |
960
4921edc4b518 fix stubexec
Meredith Howard <mhoward@roomag.org>
parents: 958
diff changeset
48 shim_filter "$bn" |
957
ea852d545173 improve stubexec
Meredith Howard <mhoward@roomag.org>
parents: 932
diff changeset
49 head -n 1
ea852d545173 improve stubexec
Meredith Howard <mhoward@roomag.org>
parents: 932
diff changeset
50 }
ea852d545173 improve stubexec
Meredith Howard <mhoward@roomag.org>
parents: 932
diff changeset
51
1112
0ae7864c4ad8 add basic nix alternative for stubs
Meredith Howard <mhoward@roomag.org>
parents: 1110
diff changeset
52 has() {
0ae7864c4ad8 add basic nix alternative for stubs
Meredith Howard <mhoward@roomag.org>
parents: 1110
diff changeset
53 type "$1" >/dev/null 2>&1
0ae7864c4ad8 add basic nix alternative for stubs
Meredith Howard <mhoward@roomag.org>
parents: 1110
diff changeset
54 }
0ae7864c4ad8 add basic nix alternative for stubs
Meredith Howard <mhoward@roomag.org>
parents: 1110
diff changeset
55
1110
e4edb1419e3f factor out bina install
Meredith Howard <mhoward@roomag.org>
parents: 1002
diff changeset
56 bina_install() {
e4edb1419e3f factor out bina install
Meredith Howard <mhoward@roomag.org>
parents: 1002
diff changeset
57 local github_repo="$1"
e4edb1419e3f factor out bina install
Meredith Howard <mhoward@roomag.org>
parents: 1002
diff changeset
58 mkdir -p ~/.local/bin
e4edb1419e3f factor out bina install
Meredith Howard <mhoward@roomag.org>
parents: 1002
diff changeset
59 cd ~/.local/bin
e4edb1419e3f factor out bina install
Meredith Howard <mhoward@roomag.org>
parents: 1002
diff changeset
60 curl -fsSL "https://bina.egoist.dev/${github_repo}?dir=." | sh
e4edb1419e3f factor out bina install
Meredith Howard <mhoward@roomag.org>
parents: 1002
diff changeset
61 cd -
e4edb1419e3f factor out bina install
Meredith Howard <mhoward@roomag.org>
parents: 1002
diff changeset
62 }
e4edb1419e3f factor out bina install
Meredith Howard <mhoward@roomag.org>
parents: 1002
diff changeset
63
992
4e3e37ce84bc Switch stubexec to self-invoke
Meredith Howard <mhoward@roomag.org>
parents: 960
diff changeset
64 stubexec "$@"

mercurial