Fix remaining two code-review findings, both verified live: 30-selfdiag.sh regex-metachar breakage (g++), fx.sh dedup collision on ] in candidate text

This commit is contained in:
2026-08-18 02:32:20 -04:00
parent d27d9a0819
commit 25ce1ca680
2 changed files with 21 additions and 4 deletions
+8 -2
View File
@@ -79,11 +79,17 @@ fx() {
out=$("$src" "$cmd" 2>/dev/null)
if [ -n "$out" ]; then
printf '%s\n' "$out" | while IFS= read -r line; do
[ -n "$line" ] && printf '[%s] %s\n' "$label" "$line"
[ -n "$line" ] && printf '%s\t%s\n' "$label" "$line"
done
[ -n "$FX_AUTO" ] && break
fi
done | awk -F'] ' '!seen[$2]++'
done | awk -F'\t' '
{
label = $1
text = substr($0, length(label) + 2)
if (!seen[text]++) print "[" label "] " text
}
'
)
chosen=""
+13 -2
View File
@@ -21,8 +21,19 @@ cmd="$1"
prog=$(printf '%s' "$cmd" | awk '{print $1}')
[ -n "$prog" ] || exit 0
[ -n "$FX_OUTPUT" ] || exit 0
printf '%s\n' "$FX_OUTPUT" | grep -qE "^[[:space:]]*${prog}[[:space:]]" || exit 0
# Literal prefix comparison (substr/index), never a regex built from
# $prog: proven broken live for program names containing ERE
# metacharacters -- e.g. "g++ foo.cpp" produced the pattern
# "^[[:space:]]*g++[[:space:]]", a malformed stacked-quantifier regex,
# and this source silently found nothing even when $FX_OUTPUT clearly
# started a line with "g++ ". Same fix applied to the emitted function
# below, since it runs the identical check on every future call.
printf '%s\n' "$FX_OUTPUT" | awk -v p="$prog" '
{ line = $0; sub(/^[ \t]*/, "", line); if (substr(line, 1, length(p) + 1) == p " ") { found = 1; exit } }
END { exit !found }
' || exit 0
cat <<FIX
${prog}(){ out=\$(command ${prog} "\$@" 2>&1); ec=\$?; if [ \$ec -ne 0 ]; then sug=\$(printf '%s\\n' "\$out" | awk '/^[ \\t]*${prog}[ \\t]/{sub(/^[ \\t]*/,""); s=\$0} END{print s}'); if [ -n "\$sug" ]; then eval "command \$sug"; return \$?; fi; fi; printf '%s\\n' "\$out"; return \$ec; }
${prog}(){ out=\$(command ${prog} "\$@" 2>&1); ec=\$?; if [ \$ec -ne 0 ]; then sug=\$(printf '%s\\n' "\$out" | awk -v p="${prog}" '{ line=\$0; sub(/^[ \\t]*/,"",line); if (substr(line,1,length(p)+1)==p" ") s=line } END{print s}'); if [ -n "\$sug" ]; then eval "command \$sug"; return \$?; fi; fi; printf '%s\\n' "\$out"; return \$ec; }
FIX