36 stubexec() { |
36 stubexec() { |
37 local real_bin="$(realbin "$0" | age_check)" |
37 local real_bin="$(realbin "$0" | age_check)" |
38 if [ -x "$real_bin" ]; then |
38 if [ -x "$real_bin" ]; then |
39 exec "$real_bin" "$@" |
39 exec "$real_bin" "$@" |
40 fi |
40 fi |
41 try_nix_run "$@" |
41 try_nix "$@" |
42 install_it |
42 try_install_callback |
43 touch "$(realbin "$0")" # In case of no updates |
|
44 stubexec "$@" |
43 stubexec "$@" |
45 } |
44 } |
46 |
45 |
47 has() { |
46 has() { |
48 type "$1" >/dev/null 2>&1 |
47 type "$1" >/dev/null 2>&1 |
49 } |
48 } |
50 |
49 |
51 try_nix_run() { |
50 try_nix() { |
52 if [ "${nix_ref:-}" ] && has nix; then |
51 [ "${nix_ref:-}" ] && has nix || return 1 |
53 # FIXME: this can be GC'd and doesn't allow running alternate commands |
52 local installed_slot="$( |
54 exec nix run "$nix_ref" -- "$@" |
53 nix profile list | perl -anE 'BEGIN { $m = shift =~ s/#/#.+/r } say $F[0] if $F[1] =~ $m' "$nix_ref" |
|
54 )" |
|
55 if [ "$installed_slot" ]; then |
|
56 nix profile upgrade "$installed_slot" |
|
57 else |
|
58 nix profile install "$nix_ref" |
55 fi |
59 fi |
|
60 # skip age check |
|
61 exec "$(realbin "$0")" "$@" |
|
62 # FIXME: so right now, this works but will check for upgrades every run past |
|
63 # the age check |
|
64 } |
|
65 |
|
66 try_install_callback() { |
|
67 install_it |
|
68 touch "$(realbin "$0")" # In case of no updates |
56 } |
69 } |
57 |
70 |
58 bina_install() { |
71 bina_install() { |
59 local github_repo="$1" |
72 local github_repo="$1" |
60 mkdir -p ~/.local/bin |
73 mkdir -p ~/.local/bin |