Skip to content

feat: make output pipeable with -n, non-auto styles#3438

Merged
keith-hall merged 2 commits intosharkdp:masterfrom
lmmx:pipe-style
Oct 18, 2025
Merged

feat: make output pipeable with -n, non-auto styles#3438
keith-hall merged 2 commits intosharkdp:masterfrom
lmmx:pipe-style

Conversation

@lmmx
Copy link
Copy Markdown
Contributor

@lmmx lmmx commented Oct 16, 2025

Background

I recently noticed I cannot pipe bat -n output anywhere (e.g. cat, other Unix tools, the clipboard via xclip) and get line numbers like nl, it just looks like cat output.

I have come across these duplicates, there may be other reports of the same thing:

I found there was an abandoned PR with the same discussion (#2983) and someone proposed a new approach, but it never got extended to a full solution.

Since that PR, lots of the machinery it proposed was added (passing style components through in the loop_through case which occurs when piped), which made this easier this time round.

I've made sure to add tests and to preserve the standard behaviour (the --style=auto case, which appears to be the CLI default, not to be confused with --style=default which is set explicitly and behaves like auto but the docs highlight that auto should be expected to pipe as plain)

Description

  • Gate the use of the SimplePrinter on plain too
  • Gate the use of the SimplePrinter (via the loop_through variable) on:
    • the number flag being passed
    • the style flag being passed with numbers in the value, or anything except auto
      • Note: the docs say that auto is "same as 'default', unless the output is piped." i.e. should pipe as plain

Bugs fixed

  • -n/--number should pipe
  • --style=numbers should pipe
  • --style=header,grid,numbers should pipe
  • --style=default should pipe
  • --style=auto should continue to not pipe (retained existing behaviour, not a bug fix)

Test cases

  • You should be able to set the -n/--number flag
  • You should be able to pass it in --style equivalently (as --style=numbers)
  • You should be able to combine it with other flags (e.g. --style=header,grid,numbers)

Integration tests added:

  • fn piped_output_with_default_style
  • fn piped_output_with_line_number_flag
  • fn piped_output_with_line_numbers_style_flag
  • fn piped_output_with_line_numbers_with_header_grid_style_flag
  • fn piped_output_with_auto_style
  • fn piped_output_with_default_style_flag
Click to show demos of existing bat behaviour
louis 🌟 ~/dev/bat $ bat Cargo.toml -r :3
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: Cargo.toml
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ [package]
   2   │ authors = ["David Peter <mail@david-peter.de>"]
   3   │ categories = ["command-line-utilities"]
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
louis 🌟 ~/dev/bat $ bat Cargo.toml -r :3 --style=grid
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
[package]
authors = ["David Peter <mail@david-peter.de>"]
categories = ["command-line-utilities"]
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
louis 🌟 ~/dev/bat $ bat Cargo.toml -r :3 --style=header
File: Cargo.toml
[package]
authors = ["David Peter <mail@david-peter.de>"]
categories = ["command-line-utilities"]
louis 🌟 ~/dev/bat $ bat Cargo.toml -r :3 --style=header,grid
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
File: Cargo.toml
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
[package]
authors = ["David Peter <mail@david-peter.de>"]
categories = ["command-line-utilities"]
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
louis 🌟 ~/dev/bat $ bat Cargo.toml -r :3 --style=header,grid,numbers
─────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
     │ File: Cargo.toml
─────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1 │ [package]
   2 │ authors = ["David Peter <mail@david-peter.de>"]
   3 │ categories = ["command-line-utilities"]
─────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
louis 🌟 ~/dev/bat $ bat Cargo.toml -r :3 --style=header,grid,numbers | cat
[package]
authors = ["David Peter <mail@david-peter.de>"]
categories = ["command-line-utilities"]
louis 🌟 ~/dev/bat $ bat Cargo.toml -r :3 --style=header,grid,numbers | cat
[package]
authors = ["David Peter <mail@david-peter.de>"]
categories = ["command-line-utilities"]
louis 🌟 ~/dev/bat $ 

Demo

No flags (implicit style=auto)

  • bat Cargo.toml -r :2 | cat

Before:

[package]
authors = ["David Peter <mail@david-peter.de>"]
categories = ["command-line-utilities"]
description = "A cat(1) clone with wings."

After: (Unchanged)

Plain

  • bat Cargo.toml -p -r :4 | cat

Before:

[package]
authors = ["David Peter <mail@david-peter.de>"]
categories = ["command-line-utilities"]
description = "A cat(1) clone with wings."

After: (Unchanged)

Line numbers only

  • bat Cargo.toml -n -r :4 | cat or bat Cargo.toml --style=numbers -r :4 | cat

Before: (As for plain)

After:

   1 [package]
   2 authors = ["David Peter <mail@david-peter.de>"]
   3 categories = ["command-line-utilities"]
   4 description = "A cat(1) clone with wings."

Full style (explicit default)

  • bat Cargo.toml --style=default -r :4 | cat

Before: (As for plain)

After:

─────┬──────────────────────────────────────────────────────────────────────────
     │ File: Cargo.toml
─────┼──────────────────────────────────────────────────────────────────────────
   1 │ [package]
   2 │ authors = ["David Peter <mail@david-peter.de>"]
   3 │ categories = ["command-line-utilities"]
   4 │ description = "A cat(1) clone with wings."
─────┴──────────────────────────────────────────────────────────────────────────

@lmmx lmmx marked this pull request as draft October 16, 2025 11:45
@lmmx lmmx changed the title feat: make output pipeable [DRAFT] feat: make output pipeable Oct 16, 2025
@lmmx lmmx closed this Oct 16, 2025
@lmmx lmmx reopened this Oct 16, 2025
@lmmx lmmx changed the title [DRAFT] feat: make output pipeable [DRAFT] feat: make output pipeable with line numbers Oct 16, 2025
@lmmx lmmx force-pushed the pipe-style branch 2 times, most recently from c68b8bd to fabd105 Compare October 16, 2025 13:10
@lmmx lmmx changed the title [DRAFT] feat: make output pipeable with line numbers [DRAFT] feat: make output pipeable with -n, non-auto styles Oct 16, 2025
@lmmx lmmx force-pushed the pipe-style branch 3 times, most recently from ee3ecc1 to 50f39f0 Compare October 16, 2025 13:29
@lmmx lmmx marked this pull request as ready for review October 16, 2025 13:35
@lmmx lmmx changed the title [DRAFT] feat: make output pipeable with -n, non-auto styles feat: make output pipeable with -n, non-auto styles Oct 16, 2025
@lmmx lmmx force-pushed the pipe-style branch 2 times, most recently from f02b7a8 to 2a95a12 Compare October 16, 2025 13:55
@lmmx
Copy link
Copy Markdown
Contributor Author

lmmx commented Oct 16, 2025

I've disabled these two tests on Windows as they are failing the CI (snapshots have one fewer terminal width char?) on 2 of the 3 Windows architectures (so if I changed it to per platform it would still not work) 🤦‍♂️

failures:
    piped_output_with_default_style_flag
    piped_output_with_line_numbers_with_header_grid_style_flag
Click to show full log

failures:

---- piped_output_with_default_style_flag stdout ----

thread 'piped_output_with_default_style_flag' panicked at /rustc/1159e78c4747b02ef996e55082b704c09b970588\library\core\src\ops\function.rs:253:5:
Unexpected stdout, failed diff original var
├── original: ─────┬──────────────────────────────────────────────────────────────────────────
│        │ STDIN
│   ─────┼──────────────────────────────────────────────────────────────────────────
│      1 │ hello
│      2 │ world
│   ─────┴──────────────────────────────────────────────────────────────────────────
├── diff: 
│   --- 	orig
│   +++ 	var
│   @@ -1 +1 @@
│   -─────┬──────────────────────────────────────────────────────────────────────────
│   +─────┬─────────────────────────────────────────────────────────────────────────
│   @@ -3 +3 @@
│   -─────┼──────────────────────────────────────────────────────────────────────────
│   +─────┼─────────────────────────────────────────────────────────────────────────
│   @@ -6 +6 @@
│   -─────┴──────────────────────────────────────────────────────────────────────────
│   +─────┴─────────────────────────────────────────────────────────────────────────
└── var as str: ─────┬─────────────────────────────────────────────────────────────────────────
         │ STDIN
    ─────┼─────────────────────────────────────────────────────────────────────────
       1 │ hello
       2 │ world
    ─────┴─────────────────────────────────────────────────────────────────────────

command=`"D:\\a\\bat\\bat\\target\\x86_64-pc-windows-msvc\\debug\\bat.exe" "--no-config" "--style=default"`
stdin=````
hello
world

`
code=0
stdout=```
─────┬─────────────────────────────────────────────────────────────────────────
│ STDIN
─────┼─────────────────────────────────────────────────────────────────────────
1 │ hello
2 │ world
─────┴─────────────────────────────────────────────────────────────────────────


stderr=""

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- piped_output_with_line_numbers_with_header_grid_style_flag stdout ----

thread 'piped_output_with_line_numbers_with_header_grid_style_flag' panicked at /rustc/1159e78c4747b02ef996e55082b704c09b970588\library\core\src\ops\function.rs:253:5:
Unexpected stdout, failed diff original var
├── original: ─────┬──────────────────────────────────────────────────────────────────────────
│        │ STDIN
│   ─────┼──────────────────────────────────────────────────────────────────────────
│      1 │ hello
│      2 │ world
│   ─────┴──────────────────────────────────────────────────────────────────────────
├── diff: 
│   --- 	orig
│   +++ 	var
│   @@ -1 +1 @@
│   -─────┬──────────────────────────────────────────────────────────────────────────
│   +─────┬─────────────────────────────────────────────────────────────────────────
│   @@ -3 +3 @@
│   -─────┼──────────────────────────────────────────────────────────────────────────
│   +─────┼─────────────────────────────────────────────────────────────────────────
│   @@ -6 +6 @@
│   -─────┴──────────────────────────────────────────────────────────────────────────
│   +─────┴─────────────────────────────────────────────────────────────────────────
└── var as str: ─────┬─────────────────────────────────────────────────────────────────────────
         │ STDIN
    ─────┼─────────────────────────────────────────────────────────────────────────
       1 │ hello
       2 │ world
    ─────┴─────────────────────────────────────────────────────────────────────────

command=`"D:\\a\\bat\\bat\\target\\x86_64-pc-windows-msvc\\debug\\bat.exe" "--no-config" "--style=header,grid,numbers"`
stdin=````
hello
world

`
code=0
stdout=```
─────┬─────────────────────────────────────────────────────────────────────────
│ STDIN
─────┼─────────────────────────────────────────────────────────────────────────
1 │ hello
2 │ world
─────┴─────────────────────────────────────────────────────────────────────────


stderr=""

@keith-hall keith-hall added this to the v0.26.0 milestone Oct 16, 2025
@LangLangBart
Copy link
Copy Markdown

I recently noticed I cannot pipe bat -n output anywhere

Isn't that what the --decorations flag has been used for ?

bat --decorations=always -nr :4 Cargo.toml | cat
   1 [package]
   2 authors = ["David Peter <mail@david-peter.de>"]
   3 categories = ["command-line-utilities"]
   4 description = "A cat(1) clone with wings."

@lmmx
Copy link
Copy Markdown
Contributor Author

lmmx commented Oct 16, 2025

I recently noticed I cannot pipe bat -n output anywhere

Isn't that what the --decorations flag has been used for ?

I meant bat -n with no further flags cannot pipe, as discussed in #3316 it is documented as the design that these should pipe, but it wasn't implemented:

The description on --style is misleading. It says "auto: same as 'full', unless the output is piped." and "full: enables all available components (default)".

This is ultimately about nicer default behaviour for piping, as #2983 was, and keeping to the original design/better ergonomics.

@LangLangBart
Copy link
Copy Markdown

Whenever the output of {{PROJECT_EXECUTABLE}} goes to a non-interactive terminal, i.e. when the
output is piped into another process or into a file, {{PROJECT_EXECUTABLE}} will act as a drop-in
replacement for cat(1) and fall back to printing the plain file contents.

bat/assets/manual/bat.1.in

Lines 131 to 135 in a730eaa

\fB\-\-decorations\fR <when>
.IP
Specify when to use the decorations that have been specified via '\-\-style'. The
automatic mode only enables decorations if an interactive terminal is detected. Possible
values: *auto*, never, always.

It makes bat's behavior more complex. The rule is no longer "always act like cat
when piped." Instead, it becomes: "act like cat when piped, unless you use
--number (which makes it behave like cat -n) or explicitly set a --style that
isn't plain or auto." While this is arguably more intuitive, it's a departure
from the simple, documented rule.

@lmmx
Copy link
Copy Markdown
Contributor Author

lmmx commented Oct 17, 2025

Ah I hadn’t seen those man page sections before.

It makes bat's behavior more complex.

I'd say it changes the behaviour rather than making it more complex.

The rule is no longer "always act like cat when piped."

Yes, that's exactly the point - this was the requested change in #2935 (agreed to be worked on in 2024, did not land in #2983).

Instead, it becomes: "act like cat when piped, unless you use --number (which makes it behave like cat -n) or explicitly set a --style that isn't plain or auto."

I think this phrasing is unnecessarily verbose. The simpler way to describe it is:

act like cat when piped, unless you explicitly set a non-auto style.

Two clarifications:

  • There's no need to mention plain in the exceptions, piping with plain style looks the same as cat anyway
  • There's no need to single out --number, it's just a style alias and is already covered by "explicitly set a style"

Based on the man page you quoted, I thought this was already the intended functionality: that the auto style adapts to piping, while explicit styles like default or numbers would work regardless.

While this is arguably more intuitive, it's a departure from the simple, documented rule.

To me, intuitive = simple. If someone explicitly requests a style with -n or --style=numbers, they expect that style when piping.

I find it undesirable for bat to behave like cat when piped, and my impression from the issue tracker is that others agree.

I understood from #2935 and the discussion on the previous PR that this behavior change was desired. If there's still disagreement about whether this should change at all, I'm not sure how to proceed. I took it I was implementing a requested feature.

The key principle: when someone explicitly requests a style, honour it. Default behaviour (no flags) is preserved for backwards compatibility.

I'll update the man page sections to reflect this behavior change:

@@ -1,3 +1,4 @@
 Whenever the output of {{PROJECT_EXECUTABLE}} goes to a non-interactive terminal, i.e. when the 
 output is piped into another process or into a file, {{PROJECT_EXECUTABLE}} will act as a drop-in 
-replacement for cat(1) and fall back to printing the plain file contents.
+replacement for cat(1) and fall back to printing the plain file contents,
+unless an explicit style is requested.
@@ -2,5 +2,6 @@
 .IP 
 Specify when to use the decorations that have been specified via '\-\-style'. The 
-automatic mode only enables decorations if an interactive terminal is detected. Possible 
-values: *auto*, never, always.
+automatic mode only enables decorations if an interactive terminal is detected. The 
+always mode will show decorations even when piping output. Possible 
+values: *auto*, never, always.

@lmmx lmmx marked this pull request as draft October 17, 2025 09:23
@lmmx lmmx changed the title feat: make output pipeable with -n, non-auto styles [WIP] feat: make output pipeable with -n, non-auto styles Oct 17, 2025
@lmmx lmmx force-pushed the pipe-style branch 3 times, most recently from b916592 to 42322b8 Compare October 17, 2025 09:51
@lmmx
Copy link
Copy Markdown
Contributor Author

lmmx commented Oct 17, 2025

  • Man page amended accordingly

I then looked for other docs with the same substring to edit likewise

louis 🌟 ~/dev/bat $ rg -l 'Specify when to use the dec'
src/bin/bat/clap_app.rs
assets/manual/bat.1.in
doc/long-help.txt
tests/syntax-tests/highlighted/Manpage/bat-0.16.man
tests/syntax-tests/source/Manpage/bat-0.16.man
  • Other docs reviewed:

    • src/bin/bat/clap_app.rs amended to produce the same as docs/long-help.txt
    • docs/long-help.txt amended to match the man page
    • tests/syntax-tests/highlighted/Manpage/bat-0.16.man - man pages for published version 0.16, left as is
    • tests/syntax-tests/source/Manpage/bat-0.16.man - man pages for published version 0.16, left as is
  • Docs tests are passing again

The README also mentions cat-like behaviour in two places (file concatenation and xclip examples), but I'd leave these as is since they still work as shown. The modifier "except if a style is set" could be added, but I think this is sufficiently intuitive/already documented that it would be unnecessary.

👍 Ready for re-review, taking back out of draft

@lmmx lmmx marked this pull request as ready for review October 17, 2025 09:51
Copy link
Copy Markdown
Collaborator

@keith-hall keith-hall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for your hard work on this one! Looks great!

@LangLangBart
Copy link
Copy Markdown

Until now, bat behaved predictably: it showed decorations only in interactive
terminals, stripping them in non‑interactive output unless explicitly forced
(e.g., --decorations=always, --color=always, or --force-colorization).

The proposed change breaks this for some flags. Users would see decorations in
non-interactive output for certain flags but not others. For example, --diff
produces decorations that don't appear in non-interactive terminals, undermining
intuitive flag usage.

I got accustomed to interactive viewing and have learned over the years that
decorations don't carry over unless forced. For the command below, I wouldn't
expect the style to appear in the output:

BAT_OPTS='--style=header,grid' bat README.md | wc -l

If line numbers in piped output is the major reason, users can set the
decorations flag in their config file or use an alias. This solves the issue
without breaking consistency.

@lmmx
Copy link
Copy Markdown
Contributor Author

lmmx commented Oct 18, 2025

Thanks for the feedback, to address your points:

The change only affects behaviour when users explicitly pass style flags like -n or --style=numbers (including when set in BAT_OPTS). Default behaviour (no flags/env vars) stays the same, so backward compatibility is preserved. This aligns with the documented behaviour of the auto style.

The principle: if someone explicitly asks for a style, honour it. This matches how other Unix tools work. cat -n preserves numbers when piped, and tail -n with multiple files preserves header decorations. See demos below.

On --diff: I tried it and since diff isn't a style component, it already uses the default auto style behaviour when piped, so no change needed there (see Diff Demo below).

On BAT_OPTS: If someone explicitly sets a style via BAT_OPTS, it's equivalent to setting it on the command line. They can add --decorations=always if they want to ensure decorations pipe.

The logic and compatibility were validated in previous reviews. The implementation is consistent with both the documentation and existing auto behaviour. I'm confident this is the right approach, but I'm open to addressing specific technical concerns if there are any.

Note

Rebased on master branch without changes

Demos

Diff Demo

Behaviour is unchanged:

louis 🌟 ~/dev/bat $ bat --diff README.md
───────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: README.md
───────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 911   │ 
 912   │ ## Project goals and alternatives
 913 ~ │ hello
 914   │ `bat` tries to achieve the following goals:
 915   │ 
───────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
louis 🌟 ~/dev/bat $ bat --diff README.md | wc -l
5
louis 🌟 ~/dev/bat $ ./target/release/bat --diff README.md | wc -l
5

Cat Demo

Comparing bat -n behavior with cat -n when piping:

louis 🌟 ~/dev/bat $ echo "hello" | cat | wc -c
6
louis 🌟 ~/dev/bat $ echo "hello" | cat -n | wc -c
13
louis 🌟 ~/dev/bat $ echo "hello" | bat | wc -c
6
louis 🌟 ~/dev/bat $ echo "hello" | bat -n | wc -c
6

With this PR, bat -n behaves like cat -n (preserves line numbers when piped):

louis 🌟 ~/dev/bat $ echo "hello" | ./target/release/bat -n | wc -c
11

Tail Demo

Headers are preserved when piped (similar to bat's header/grid decorations):

louis 🌟 ~/dev/bat $ tail -n999 <(echo "foo") <(echo "bar")
==> /dev/fd/63 <==
foo

==> /dev/fd/62 <==
bar
louis 🌟 ~/dev/bat $ tail -n999 <(echo "foo") <(echo "bar") | cat
==> /dev/fd/63 <==
foo

==> /dev/fd/62 <==
bar

@keith-hall
Copy link
Copy Markdown
Collaborator

@LangLangBart thanks for sharing your concerns. I understand that these changes may break behavior you are used to. But, as we have had a number of people open issues about it, and the wording in the documentation generally suggesting it should work the way it does in this PR, along with the cat -n piping behavior, I'm going to merge it. If we get lots of complaints, we can certainly revisit it again. Thanks for your understanding.

@keith-hall keith-hall changed the title [WIP] feat: make output pipeable with -n, non-auto styles feat: make output pipeable with -n, non-auto styles Oct 18, 2025
@keith-hall keith-hall merged commit 83ffd1e into sharkdp:master Oct 18, 2025
24 checks passed
@lmmx lmmx deleted the pipe-style branch October 18, 2025 19:05
@keith-hall
Copy link
Copy Markdown
Collaborator

Just an FYI, apparently some workflows (aliasing cat with specific arguments) have been disrupted due to this change: #3445
Maybe you can help think of the best way forward please @lmmx. Ideally we want to make everyone happy 😅

@lmmx
Copy link
Copy Markdown
Contributor Author

lmmx commented Oct 20, 2025

Sorry @keith-hall I was reviewing bug reports in here this morning and did not spot this 🤦‍♂️ Taking a look now

@lmmx
Copy link
Copy Markdown
Contributor Author

lmmx commented Oct 20, 2025

Maybe you can help think of the best way forward please @lmmx.

That issue seems to be addressed already, not sure what the ask is here @keith-hall but happy to think about any further accomodations. Were there any other reports or just this one so far?

That cat <&… pattern can be seen elsewhere (source) and so can command cat <&… (source)

I personally think aliasing cat with a style is a bit radical, and I think it’s fair to expect that to not be smooth sailing!

It’s much more common if you look at people’s shared dotfiles for them to do it with --style=plain or just bat alone(source), neither of which would be affected.

@keith-hall
Copy link
Copy Markdown
Collaborator

That issue seems to be addressed already, not sure what the ask is here @keith-hall but happy to think about any further accomodations. Were there any other reports or just this one so far?

Just this one so far that I have seen. I guess I just want us to be prepared in case more come in. I completely agree about aliasing cat 😉 but as it is mentioned in the Readme, we kinda have to support it and try to behave in a way that doesn't break too much...

I was wondering whether it would be safer to only fix -n specifically when it is on the command line (ignoring env vars and config) and in other cases, update the documentation to refer to --decorations. But that also complicates things from a user's perspective - having some arguments work differently when on the command line would be highly unintuitive. So I don't really like that solution 😅

Probably we can leave things as they are for now. Thanks for checking common usage 👍

@lokesh-balla
Copy link
Copy Markdown

I personally think aliasing cat with a style is a bit radical, and I think it’s fair to expect that to not be smooth sailing!

I do understand that aliasing cat is bound to break sometimes but in this case I don't see why it is considered radical though.

The way I see it the decorations behave in a confusing way now.

# displays with decorations but does not carry the decorations when piped to something else
bat --paging="never" filename.txt
# displays with decorations and carries the decorations when piped to something else
export BAT_STYLE="header-filename,header-filesize,grid"
bat --paging="never" filename.txt
or
bat --style="header-filename,header-filesize,grid" --paging="never" filename.txt

I always assumed not carrying decorations was deliberate choice to avoid issues when piped to something else but if that is not the case then may be we should unify behaviour in the above case as well.

@LangLangBart
Copy link
Copy Markdown

Probably we can leave things as they are for now.

is @sharkdp still around ?

@lmmx
Copy link
Copy Markdown
Contributor Author

lmmx commented Oct 21, 2025

I personally think aliasing cat with a style is a bit radical, and I think it's fair to expect that to not be smooth sailing!

I do understand that aliasing cat is bound to break sometimes but in this case I don't see why it is considered radical though.

Perhaps "radical" was too strong - I meant that using bat as a "drop-in replacement" (as quoted in the man page) refers to unconfigured behaviour, whilst custom style configurations are a different use case. The PR preserves default (unconfigured) behaviour; extending that guarantee to all possible style configurations would require different design choices.

tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Oct 22, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [sharkdp/bat](https://github.com/sharkdp/bat) | minor | `v0.25.0` -> `v0.26.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>sharkdp/bat (sharkdp/bat)</summary>

### [`v0.26.0`](https://github.com/sharkdp/bat/blob/HEAD/CHANGELOG.md#v0260)

[Compare Source](sharkdp/bat@v0.25.0...v0.26.0)

#### Features

- Add build for windows/ARM64 platform. [#&#8203;3190](sharkdp/bat#3190) ([@&#8203;alcroito](https://github.com/alcroito))
- Add paging to `--list-themes`, see MR [#&#8203;3239](sharkdp/bat#3239) ([@&#8203;einfachIrgendwer0815](https://github.com/einfachIrgendwer0815))
- Support negative relative line ranges, e.g. `bat -r :-10` / `bat -r='-10:'`, see [#&#8203;3068](sharkdp/bat#3068) ([@&#8203;ajesipow](https://github.com/ajesipow))
- Support context in line ranges, e.g. `bat -r 30::5` /  `bat -r 30:40:5`, see [#&#8203;3345](sharkdp/bat#3345) ([@&#8203;cavanaug](https://github.com/cavanaug))
- Add built-in 'minus' pager, e.g. `bat --pager=builtin` see MR [#&#8203;3402](sharkdp/bat#3402) ([@&#8203;academician](https://github.com/academician))

#### Bugfixes

- Fix UTF-8 BOM not being stripped for syntax detection, see [#&#8203;3314](sharkdp/bat#3314) ([@&#8203;krikera](https://github.com/krikera))
- Fix `BAT_THEME_DARK` and `BAT_THEME_LIGHT` being ignored, see issue [#&#8203;3171](sharkdp/bat#3171) and MR [#&#8203;3168](sharkdp/bat#3168) ([@&#8203;bash](https://github.com/bash))
- Prevent `--list-themes` from outputting default theme info to stdout when it is piped, see [#&#8203;3189](sharkdp/bat#3189) ([@&#8203;einfachIrgendwer0815](https://github.com/einfachIrgendwer0815))
- Rename some submodules to fix Dependabot submodule updates, see issue [#&#8203;3198](sharkdp/bat#3198) and MR [#&#8203;3201](sharkdp/bat#3201) ([@&#8203;victor-gp](https://github.com/victor-gp))
- Make highlight tests fail when new syntaxes don't have fixtures MR [#&#8203;3255](sharkdp/bat#3255) ([@&#8203;dan-hipschman](https://github.com/dan-hipschman))
- Fix crash for multibyte characters in file path, see issue [#&#8203;3230](sharkdp/bat#3230) and MR [#&#8203;3245](sharkdp/bat#3245) ([@&#8203;HSM95](https://github.com/HSM95))
- Add missing mappings for various bash/zsh files, see MR [#&#8203;3262](sharkdp/bat#3262) ([@&#8203;AdamGaskins](https://github.com/AdamGaskins))
- Send all bat errors to stderr by default, see [#&#8203;3336](sharkdp/bat#3336) ([@&#8203;JerryImMouse](https://github.com/JerryImMouse))
- Make --map-syntax target case insensitive to match --language, see [#&#8203;3206](sharkdp/bat#3206) ([@&#8203;keith-hall](https://github.com/keith-hall))
- Correctly determine the end of the line in UTF16LE/BE input [#&#8203;3369](sharkdp/bat#3369) ([@&#8203;keith-hall](https://github.com/keith-hall))
- `--style=changes` no longer prints a two-space indent when the file is unmodified, see issue [#&#8203;2710](sharkdp/bat#2710) and MR [#&#8203;3406](sharkdp/bat#3406) ([@&#8203;jyn514](https://github.com/jyn514))
- Add missing shell completions, see [#&#8203;3411](sharkdp/bat#3411) ([@&#8203;keith-hall](https://github.com/keith-hall))
- Execute help/version/diagnostic commands even with invalid config/arguments present, see [#&#8203;3414](sharkdp/bat#3414) ([@&#8203;keith-hall](https://github.com/keith-hall))
- Fixed line numbers (`-n`) and style components not printing when piping output, see issue [#&#8203;2935](sharkdp/bat#2935) and MR [#&#8203;3438](sharkdp/bat#3438) ([@&#8203;lmmx](https://github.com/lmmx))

#### Other

- Update base16 README links to community driven base16 work [#&#8203;2871](sharkdp/bat#2871) ([@&#8203;JamyGolden](https://github.com/JamyGolden))
- Work around build failures when building `bat` from vendored sources [#&#8203;3179](sharkdp/bat#3179) ([@&#8203;dtolnay](https://github.com/dtolnay))
- CICD: Stop building for x86\_64-pc-windows-gnu which fails [#&#8203;3261](sharkdp/bat#3261) (Enselic)
- CICD: replace windows-2019 runners with windows-2025 [#&#8203;3339](sharkdp/bat#3339) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
- Build script: replace string-based codegen with quote-based codegen [#&#8203;3340](sharkdp/bat#3340) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
- Improve code coverage of `--list-languages` parameter [#&#8203;2942](sharkdp/bat#2942) ([@&#8203;sblondon](https://github.com/sblondon))
- Only start offload worker thread when there's more than 1 core [#&#8203;2956](sharkdp/bat#2956) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
- Update terminal-colorsaurus (the library used for dark/light detection) to 1.0, see [#&#8203;3347](sharkdp/bat#3347) ([@&#8203;bash](https://github.com/bash))
- Update console dependency to 0.16, see [#&#8203;3351](sharkdp/bat#3351) ([@&#8203;musicinmybrain](https://github.com/musicinmybrain))
- Fixed some typos [#&#8203;3244](sharkdp/bat#3244) ([@&#8203;ssbarnea](https://github.com/ssbarnea))
- Update onig\_sys dependency to 69.9.1 to fix a gcc build failure [#&#8203;3400](sharkdp/bat#3400) ([@&#8203;CosmicHorrorDev](https://github.com/CosmicHorrorDev))
- Add a cargo feature (`vendored-libgit2`) to build with vendored libgit2 version without depending on the system's one [#&#8203;3426](sharkdp/bat#3426) ([@&#8203;0x61nas](https://github.com/0x61nas))
- Update syntect dependency to v5.3.0 to fix a few minor bugs, see [#&#8203;3410](sharkdp/bat#3410) ([@&#8203;keith-hall](https://github.com/keith-hall))

#### Syntaxes

- Add syntax mapping for `paru` configuration files [#&#8203;3182](sharkdp/bat#3182) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
- Add support for [Idris 2 programming language](https://www.idris-lang.org/) [#&#8203;3150](sharkdp/bat#3150) ([@&#8203;buzden](https://github.com/buzden))
- Add syntax mapping for `nix`'s '`flake.lock` lockfiles [#&#8203;3196](sharkdp/bat#3196) ([@&#8203;odilf](https://github.com/odilf))
- Improvements to CSV/TSV highlighting, with autodetection of delimiter and support for TSV files, see [#&#8203;3186](sharkdp/bat#3186) ([@&#8203;keith-](https://github.com/keith-)
- Improve (Sys)log error highlighting, see [#&#8203;3205](sharkdp/bat#3205) ([@&#8203;keith-hall](https://github.com/keith-hall))
- Map `ndjson` extension to JSON syntax, see [#&#8203;3209](sharkdp/bat#3209) ([@&#8203;keith-hall](https://github.com/keith-hall))
- Map files with `csproj`, `vbproj`, `props` and `targets` extensions to XML syntax, see [#&#8203;3213](sharkdp/bat#3213) ([@&#8203;keith-hall](https://github.com/keith-hall))
- Add debsources syntax to highlight `/etc/apt/sources.list` files, see [#&#8203;3215](sharkdp/bat#3215) ([@&#8203;keith-hall](https://github.com/keith-hall))
- Add syntax definition and test file for GDScript highlighting, see [#&#8203;3236](sharkdp/bat#3236) ([@&#8203;chetanjangir0](https://github.com/chetanjangir0))
- Add syntax test file for Odin highlighting, see [#&#8203;3241](sharkdp/bat#3241) ([@&#8203;chetanjangir0](https://github.com/chetanjangir0))
- Update quadlet syntax mapping rules to cover quadlets in subdirectories [#&#8203;3299](sharkdp/bat#3299) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
- Add syntax Typst [#&#8203;3300](sharkdp/bat#3300) ([@&#8203;cskeeters](https://github.com/cskeeters))
- Map `.mill` files to Scala syntax for Mill build tool configuration files [#&#8203;3311](sharkdp/bat#3311) ([@&#8203;krikera](https://github.com/krikera))
- Add syntax highlighting for VHDL, see [#&#8203;3337](sharkdp/bat#3337) ([@&#8203;JerryImMouse](https://github.com/JerryImMouse))
- Add syntax mapping for certbot certificate configuration [#&#8203;3338](sharkdp/bat#3338) ([@&#8203;cyqsimon](https://github.com/cyqsimon))
- Update Lean syntax from Lean 3 to Lean 4 [#&#8203;3322](sharkdp/bat#3322) ([@&#8203;YDX-2147483647](https://github.com/YDX-2147483647))
- Map `.flatpakref` and `.flatpakrepo` files to INI syntax [#&#8203;3353](sharkdp/bat#3353) ([@&#8203;Ferenc-](https://github.com/Ferenc-))
- Update hosts syntax [#&#8203;3368](sharkdp/bat#3368) ([@&#8203;keith-hall](https://github.com/keith-hall))
- Map `.kshrc` files to Bash syntax [#&#8203;3364](sharkdp/bat#3364) ([@&#8203;ritoban23](https://github.com/ritoban23))
- Map `/var/log/dmesg` files to Syslog syntax [#&#8203;3412](sharkdp/bat#3412) ([@&#8203;keith-hall](https://github.com/keith-hall))
- Add syntax definition and test file for Go modules(`go.mod` and `go.sum`) highlighting, see [#&#8203;3424](sharkdp/bat#3424) ([@&#8203;DarkMatter-999](https://github.com/DarkMatter-999))
- Syntax highlighting for typescript code blocks within Markdown files, see [#&#8203;3435](sharkdp/bat#3435) ([@&#8203;MuntasirSZN](https://github.com/MuntasirSZN))

#### Themes

- Add Catppuccin, see [#&#8203;3317](sharkdp/bat#3317) ([@&#8203;SchweGELBin](https://github.com/SchweGELBin))
- Updated Catppuccin, see [#&#8203;3333](sharkdp/bat#3333) ([@&#8203;SchweGELBin](https://github.com/SchweGELBin))
- Updated gruvbox, see [#&#8203;3372](sharkdp/bat#3372) ([@&#8203;Nicholas42](https://github.com/Nicholas42))
- Updated GitHub theme, see [#&#8203;3382](sharkdp/bat#3382) ([@&#8203;CosmicHorrorDev](https://github.com/CosmicHorrorDev))
- Updated ANSI theme to highlight JSON object keys differently from values, see [#&#8203;3413](sharkdp/bat#3413) ([@&#8203;keith-hall](https://github.com/keith-hall))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xNTEuMSIsInVwZGF0ZWRJblZlciI6IjQxLjE1Mi45IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
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.

4 participants