Repository navigation
fix(prompt,printf): correct \j \l \D and leading-dash printf - #1111
Merged
Merged
Conversation
…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
force-pushed
the
fix/prompt-trio
branch
from
October 23, 2026 01:22
e56b7b2 to
d48e256
Compare
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.