.lib/sh/stubexec.sh

changeset 1112
0ae7864c4ad8
parent 1110
e4edb1419e3f
child 1114
fd7f92c949fb
--- a/.lib/sh/stubexec.sh
+++ b/.lib/sh/stubexec.sh
@@ -38,11 +38,23 @@ stubexec() {
   if [ -x "$real_bin" ]; then
     exec "$real_bin" "$@"
   fi
+  try_nix_run "$@"
   install_it
   touch "$(realbin "$0")"  # In case of no updates
   stubexec "$@"
 }
 
+has() {
+  type "$1" >/dev/null 2>&1
+}
+
+try_nix_run() {
+  if [ "${nix_ref:-}" ] && has nix; then
+    # FIXME: this can be GC'd and doesn't allow running alternate commands
+    exec nix run "$nix_ref" -- "$@"
+  fi
+}
+
 bina_install() {
   local github_repo="$1"
   mkdir -p ~/.local/bin

mercurial