Fix real hardware/busybox breakage: dead compgen dependency, unreliable sourced-path detection, and fork-heavy pipelines in fx sources; verified against busybox ash+awk directly

This commit is contained in:
2026-08-17 23:19:07 -04:00
parent b4d619de8a
commit df3c328424
5 changed files with 51 additions and 14 deletions
+11 -3
View File
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
# PATH-fuzzy source: if the first word isn't a known command, alias, or
# function, offer a function wrapping the closest-spelled real command
# as a candidate -- as a fix you approve through the normal f() flow,
@@ -7,6 +7,12 @@
# otherwise), so an alias-based fix silently does nothing when f/fx run
# inside a script.
#
# Pure POSIX: walks $PATH directly instead of `compgen -c`, which is a
# bash-only builtin and does not exist under busybox ash -- this source
# used to be dead weight on exactly the minimal/embedded shells this
# project targets. Tested against busybox ash + busybox awk directly,
# not just bash + gawk.
#
# Uses Damerau-Levenshtein-lite (edit distance + adjacent transposition)
# so the canonical "gti" -> "git" typo scores 1, not 2 -- plain Hamming
# or substitution-only distance ties it with unrelated 3-letter commands
@@ -15,9 +21,11 @@ cmd="$1"
first_word=$(printf '%s' "$cmd" | awk '{print $1}')
[ -n "$first_word" ] || exit 0
command -v "$first_word" >/dev/null 2>&1 && exit 0
type "$first_word" >/dev/null 2>&1 && exit 0
compgen -c 2>/dev/null | sort -u | awk -v target="$first_word" '
IFS=:
for d in $PATH; do
ls "$d" 2>/dev/null
done | sort -u | awk -v target="$first_word" '
function min3(a, b, c) { return (a < b ? (a < c ? a : c) : (b < c ? b : c)) }
function distance(a, b, n, m, i, j, ca, cb, cost, tmp) {
n = length(a); m = length(b)