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:
Regular → Executable
+19
-9
@@ -12,8 +12,15 @@
|
||||
# fx some-command --that --might --fail
|
||||
#
|
||||
# Env vars:
|
||||
# FX_SOURCES_DIR override the sources directory (default: sources.d
|
||||
# next to this script)
|
||||
# FX_SOURCES_DIR the sources directory. Defaults to ./contrib/fx/sources.d
|
||||
# (i.e. source this file from the repo root). There is no
|
||||
# portable way for a *sourced* POSIX shell file to learn
|
||||
# its own path -- $0 is the enclosing shell's name, and
|
||||
# bash's BASH_SOURCE has no equivalent in dash/ash, so
|
||||
# this does not try to be clever about it. Anything
|
||||
# other than "source from repo root" (a different cwd,
|
||||
# a temp dir a la bootstrap.sh) must set this explicitly
|
||||
# *before* sourcing this file.
|
||||
# FX_AUTO if set, auto-pick the top candidate instead of
|
||||
# showing a picker
|
||||
# FX_NO_PROBE if set, skip fx's own diagnostic run of the command
|
||||
@@ -32,14 +39,17 @@
|
||||
# Adding a source: drop a new executable file in sources.d/ that follows
|
||||
# the contract above. Nothing else to register or edit.
|
||||
|
||||
# $0 is the enclosing shell's name when this file is *sourced*, not this
|
||||
# file's own path -- ${BASH_SOURCE[0]} is reliable under bash; for other
|
||||
# POSIX shells, set FX_SOURCES_DIR explicitly before sourcing this file.
|
||||
_fx_self="${BASH_SOURCE:-$0}"
|
||||
FX_SOURCES_DIR="${FX_SOURCES_DIR:-$(CDPATH= cd -- "$(dirname -- "$_fx_self")" 2>/dev/null && pwd)/sources.d}"
|
||||
unset _fx_self
|
||||
# Resolved to an absolute path *now*, at source time -- a relative
|
||||
# default would silently re-resolve against whatever cwd happens to be
|
||||
# active later when fx() is actually called, which is almost never the
|
||||
# repo root in practice.
|
||||
FX_SOURCES_DIR="${FX_SOURCES_DIR:-$(pwd)/contrib/fx/sources.d}"
|
||||
|
||||
fx() {
|
||||
if [ ! -d "$FX_SOURCES_DIR" ]; then
|
||||
echo "fx: FX_SOURCES_DIR '$FX_SOURCES_DIR' not found -- no sources will fire." >&2
|
||||
echo "fx: set FX_SOURCES_DIR before sourcing fx.sh if not running from the repo root." >&2
|
||||
fi
|
||||
cmd="$*"
|
||||
|
||||
FX_OUTPUT=""
|
||||
@@ -55,7 +65,7 @@ fx() {
|
||||
candidates=$(
|
||||
for src in "$FX_SOURCES_DIR"/*; do
|
||||
[ -x "$src" ] || continue
|
||||
label=$(basename "$src")
|
||||
label="${src##*/}"
|
||||
"$src" "$cmd" 2>/dev/null | while IFS= read -r line; do
|
||||
[ -n "$line" ] && printf '[%s] %s\n' "$label" "$line"
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user