1 cache="${XDG_CACHE_HOME:-$HOME/.cache}/stubexec" |
1 cache="${XDG_CACHE_HOME:-$HOME/.cache}/stubexec" |
2 |
2 |
3 stubexec() { |
3 stubexec() { |
|
4 mkdir -p "$cache" |
|
5 |
4 local real_bin="$(realbin "$0")" |
6 local real_bin="$(realbin "$0")" |
5 if [ ! -x "$real_bin" ] || age_check $0; then |
7 if [ ! -x "$real_bin" ] || age_check $0; then |
6 try_nix "$@" || |
8 install_it |
7 try_install_callback |
|
8 touch_checktime "$0" |
9 touch_checktime "$0" |
9 stubexec "$@" |
10 stubexec "$@" |
10 fi |
11 fi |
11 exec "$real_bin" "$@" |
12 exec "$real_bin" "$@" |
12 } |
13 } |
13 |
14 |
14 db() { |
|
15 mkdir -p "$cache" |
|
16 kv "$cache/db" "$@" |
|
17 } |
|
18 |
|
19 touch_checktime() { |
15 touch_checktime() { |
20 db touch "$(basename $1)" |
16 kv "$cache/db" touch "$(basename $1)" |
21 } |
17 } |
22 |
18 |
23 age_check() { |
19 age_check() { |
24 db age_days_gt "$(basename $1)" "${age_limit:-90}" |
20 kv "$cache/db" age_days_gt "$(basename $1)" "${age_limit:-90}" |
25 } |
21 } |
26 |
22 |
27 realpath() { |
23 realpath() { |
28 local dir="$(dirname -- "$1")" |
24 local dir="$(dirname -- "$1")" |
29 local file="$(basename -- "$1")" |
25 local file="$(basename -- "$1")" |
55 |
51 |
56 has() { |
52 has() { |
57 type "$1" >/dev/null 2>&1 |
53 type "$1" >/dev/null 2>&1 |
58 } |
54 } |
59 |
55 |
60 try_nix() { |
|
61 [ "${nix_ref:-}" ] && has nix || return 1 |
|
62 |
|
63 local installed_slot="$( |
|
64 nix profile list | perl -anE 'BEGIN { $m = shift =~ s/#/#.+/r } say $F[0] if $F[1] =~ $m' "$nix_ref" |
|
65 )" |
|
66 if [ "$installed_slot" ]; then |
|
67 nix profile upgrade "$installed_slot" |
|
68 else |
|
69 nix profile install "$nix_ref" |
|
70 fi |
|
71 } |
|
72 |
|
73 try_install_callback() { |
|
74 install_it |
|
75 } |
|
76 |
|
77 bina_install() { |
56 bina_install() { |
78 local github_repo="$1" |
57 local github_repo="$1" |
79 mkdir -p ~/.local/bin |
58 mkdir -p ~/.local/bin |
80 cd ~/.local/bin |
59 cd ~/.local/bin |
81 curl -fsSL "https://bina.egoist.dev/${github_repo}?dir=." | sh |
60 curl -fsSL "https://bina.egoist.dev/${github_repo}?dir=." | sh |