Skip to content

fix(prompt,printf): correct \j \l \D and leading-dash printf - #1111

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/prompt-trio
Oct 23, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/prompt-trio

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #1098, #1099, #1100. (1) \j was a hardcoded 0 stub; now counts non-Completed jobs (GNU parse.y:6594 count_all_jobs). (2) \l reads ttyname(0) basename else literal tty (was wrong TTY/SSH_TTY env lookup); \D{} defaults to %X; unknown strftime %x drops % keeps char (glibc behavior, verified for \D and %()T). (3) printf leading-dash: option = len>1 dash-word, error names -+2nd char, -v missing-arg gets usage line (GNU printf.def/bashgetopt). Tests: lib 693 + prompt/printf/job cli green; GNU parity byte-identical (job counts, tty name, date, printf errors+rc). One pre-existing unrelated cli failure (missing examples fixture on Termux) unchanged.

…1098 #1099 #1100)

\j (parse.y:6594-6596 case 'j' -> itos(count_all_jobs());
jobs.c:5130 count_all_jobs counts jobs[i] && DEADJOB==0, all non-dead):
prompt_job_count was a hardcoded 0. Count job-table entries whose
state != Completed (Running and Stopped both count). Job tracking
itself was already correct; only the expansion lookup was stubbed.

\l (parse.y:6598-6607 case 'l': ttyname(fileno(stdin)) basename,
else literal "tty"): prompt_terminal_basename read $TTY/$SSH_TTY
and returned "" when unset. Use libc ttyname(0) basename on unix
("tty" fallback, also the non-unix fallback); drop the env lookup.

\D{} (parse.y:6390-6425 case 'D': empty timefmt becomes "%X" before
the strftime call): decode_prompt_date_escape passed "" through to
strftime_subset, which rendered "". Map empty to "%X".

\D{%N} (parse.y case 'D' + printf.def %()T both delegate to system
strftime; glibc drops unknown %x to bare x -- probe-verified on
bash 5.3.20: \D{%N} -> N, %(%N)T -> N): strftime_subset kept the
literal "%N". Push only the character for unknown specifiers
(%% stays %, trailing lone % stays %).

printf leading dash (builtins/printf.def:297 internal_getopt(list,"v:");
builtins/bashgetopt.c:56,98-99 errstr={'-',offending_char} via
sh_invalidopt; NOTOPT (s)[1]=='\0' is not an option): report "-"+2nd
char ("--" for '--- %s') instead of the whole word; treat bare "-"
as the format (prints "-", rc 0); print the usage line for missing
-v argument (needarg + builtin_usage, both lines like GNU).

Repro (script-file, bash 5.3.20 vs fixed binary): 1098 1/2/0,
1099 L:[tty] N:[N] E:[%X time], 1100 "--: invalid option"+usage rc=2.
cargo fmt clean; cargo test --lib green (693 passed); related
cli_tests (prompt/printf/job) green -- sole failure is the
pre-existing missing-submodule fixture
examples::gnu_zprintf_usage_guard_exits_before_body (127 vs 2,
third_party/bash not checked out in this worktree; passes in the
main checkout).
@caomengxuan666
caomengxuan666 merged commit 153c540 into master Oct 23, 2026
6 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member Author

Rebased onto post-#1181 master and force-pushed as d48e256a. Single trivial conflict in printf.rs (kept master's #1125 usage-line comment); no duplicates dropped. No dedicated regression file in the PR — adjacent prompt (issue757, issue431, issue393) and printf executor suites all green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] \j always expands to 0 despite live background jobs

1 participant