Repository navigation
feat: implement -b / --number-nonblank for cat -b compatibility - #3857
Merged
Merged
Conversation
Contributor
|
@MeGaurav4 are you still working on this? if not, I can start from your work and credit you on a new pr and fix the failing ci checks |
Adds a `-b` / `--number-nonblank` flag that numbers only non-blank lines. Blank lines (those containing only the line terminator) are printed without a number and don't advance the counter, matching `cat -b` behaviour. - `-b` implies `--style=numbers` (same as `-n`), but only counts non-blank lines - `-b` takes precedence over `-n`: both `-bn` and `-nb` behave like `-b` - `-bp` disables numbering (plain mode wins) - Works with files, stdin, and piped output (like `-n`) Closes sharkdp#3856.
Contributor
Author
|
Hey Tyce, thanks for checking in, and thanks for the offer either way. Still working on this: I've merged current master into the branch and fixed the failing |
keith-hall
approved these changes
Aug 11, 2026
2 tasks done
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.
Implements
cat -bcompatibility via-b/--number-nonblank.Behaviour
do not advance the line counter
-btakes precedence over-n; both-bnand-nbproduce nonblank numbering-bpdisables numbering (plain mode wins)Implementation
Core change is in
src/controller.rs: whennumber_nonblankis set,the line counter is not incremented for lines whose buffer contains
only
\r/\nbytes. Insrc/printer.rsthe decoration enginereceives
line_number = 0as sentinel for those lines, andLineNumberDecoration::generatereturns empty gutter spaces in thatcase. The raw-arg scanner in
App::new()was extended to detect-bthe same way it detects
-n(so it works with combined short flagslike
-pb/-bp).Testing
-b,-bin loop-through mode,-bn/-nbprecedence,-bpoverride, piped stdinCloses #3856.