Ask the bb on PATH who it is before handing it a script
`scripts/bb` takes any `bb` it finds as babashka, and bazel's launcher
calls itself that too. On a host with one of those ahead of the shell's,
every recipe here answered with
Command 'scripts/tui.bb' not found. Try 'bb help'
which reads as a missing script rather than as the wrong program — and it
is every recipe, since they all start here.
The version line is the cheapest question babashka answers and the one
nothing else answers the same way. An impostor now falls through to the
flake, or to the container, which is where the script wanted to be.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>57c6de2 parent: 1e8b590 modified
scripts/bb +10 -2 | @@ -16,7 +16,12 @@ | ||
| 16 | 16 | # Three answers, in order: |
| 17 | 17 | # |
| 18 | 18 | # bb on PATH the dev shell puts one there, and so does a machine that |
| 19 | -# has its own; either is what the caller meant | |
| 19 | +# has its own; either is what the caller meant — as long as | |
| 20 | +# it is babashka. `bb` is also what bazel's own launcher | |
| 21 | +# calls itself, and a host with one of those ahead of the | |
| 22 | +# shell's answered every recipe here with "Command | |
| 23 | +# 'scripts/tui.bb' not found. Try 'bb help'", which reads as | |
| 24 | +# a missing script rather than the wrong program | |
| 20 | 25 | # the flake built once and kept alive by the symlink under build/, |
| 21 | 26 | # which is a gc root as well as a cache |
| 22 | 27 | # the container nix is not on every host this runs on — see CLAUDE.md — |
| @@ -26,7 +31,10 @@ set -e | ||
| 26 | 31 | |
| 27 | 32 | root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) |
| 28 | 33 | |
| 29 | -if command -v bb >/dev/null 2>&1; then | |
| 34 | +# Asking it who it is, rather than trusting the name: the version line is the | |
| 35 | +# cheapest question babashka answers and the one nothing else answers the same | |
| 36 | +# way. | |
| 37 | +if command -v bb >/dev/null 2>&1 && bb --version 2>/dev/null | grep -qi '^babashka'; then | |
| 30 | 38 | exec bb "$@" |
| 31 | 39 | fi |
| 32 | 40 | |
| @@ -16,7 +16,12 @@ | |||
| 16 | # Three answers, in order: | 16 | # Three answers, in order: |
| 17 | # | 17 | # |
| 18 | # bb on PATH the dev shell puts one there, and so does a machine that | 18 | # bb on PATH the dev shell puts one there, and so does a machine that |
| 19 | -# has its own; either is what the caller meant | 19 | +# has its own; either is what the caller meant — as long as |
| 20 | +# it is babashka. `bb` is also what bazel's own launcher | ||
| 21 | +# calls itself, and a host with one of those ahead of the | ||
| 22 | +# shell's answered every recipe here with "Command | ||
| 23 | +# 'scripts/tui.bb' not found. Try 'bb help'", which reads as | ||
| 24 | +# a missing script rather than the wrong program | ||
| 20 | # the flake built once and kept alive by the symlink under build/, | 25 | # the flake built once and kept alive by the symlink under build/, |
| 21 | # which is a gc root as well as a cache | 26 | # which is a gc root as well as a cache |
| 22 | # the container nix is not on every host this runs on — see CLAUDE.md — | 27 | # the container nix is not on every host this runs on — see CLAUDE.md — |
| @@ -26,7 +31,10 @@ set -e | |||
| 26 | 31 | ||
| 27 | root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) | 32 | root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) |
| 28 | 33 | ||
| 29 | -if command -v bb >/dev/null 2>&1; then | 34 | +# Asking it who it is, rather than trusting the name: the version line is the |
| 35 | +# cheapest question babashka answers and the one nothing else answers the same | ||
| 36 | +# way. | ||
| 37 | +if command -v bb >/dev/null 2>&1 && bb --version 2>/dev/null | grep -qi '^babashka'; then | ||
| 30 | exec bb "$@" | 38 | exec bb "$@" |
| 31 | fi | 39 | fi |
| 32 | 40 | ||