1
0
mirror of https://github.com/sharkdp/bat synced 2026-08-11 20:11:43 +00:00

feat: implement -b / --number-nonblank for cat -b compatibility

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 #3856.
This commit is contained in:
MeGaurav4
2026-07-24 22:26:50 +05:30
parent 78951393e2
commit 061fb216cb
10 changed files with 168 additions and 6 deletions
+10
View File
@@ -83,6 +83,16 @@ Options:
-n, --number
Only show line numbers, no other decorations. This is an alias for '--style=numbers'
-b, --number-nonblank
Only show line numbers for non-blank lines, no other decorations. This is an alias for
'--style=numbers'. Non-blank lines are lines that contain any character before the line
ending, including spaces and tabs. When used together with --number (-n),
--number-nonblank (-b) takes precedence.
Example:
printf 'alpha\n\nbeta\n' | bat -b
numbers 'alpha' and 'beta', but skips the empty line.
--color <when>
Specify when to use colored output. The automatic mode only enables colors if an
interactive terminal is detected - colors are automatically disabled if the output goes to
+2
View File
@@ -33,6 +33,8 @@ Options:
Truncate all lines longer than screen width. Alias for '--wrap=never'.
-n, --number
Show line numbers (alias for '--style=numbers').
-b, --number-nonblank
Show line numbers for non-blank lines only (alias for '--style=numbers').
--color <when>
When to use colors (*auto*, never, always).
--italic-text <when>