From 626154317fd888230cf1218cb2ba2565c1b3174e Mon Sep 17 00:00:00 2001 From: dddffgg Date: Sat, 31 Jan 2026 16:40:59 +0800 Subject: [PATCH 01/16] feat: add quiet_empty config option --- src/config.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/config.rs b/src/config.rs index aa223186..7209c2fd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -107,6 +107,9 @@ pub struct Config<'a> { // Whether or not to strip ANSI escape codes from the input pub strip_ansi: StripAnsiMode, + + /// Whether or not to produce no output when input is empty + pub quiet_empty: bool, } #[cfg(all(feature = "minimal-application", feature = "paging"))] From 53a10e0b0a93d3979bf3c6a641f353b5156914a6 Mon Sep 17 00:00:00 2001 From: dddffgg Date: Sat, 31 Jan 2026 16:41:13 +0800 Subject: [PATCH 02/16] feat: add --quiet-empty CLI flag --- src/bin/bat/clap_app.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index acb505ee..10bf7a8b 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -643,6 +643,18 @@ pub fn build_app(interactive_output: bool) -> Command { .hide_short_help(true) .help("Show diagnostic information for bug reports."), ) + .arg( + Arg::new("quiet-empty") + .long("quiet-empty") + .short('E') + .action(ArgAction::SetTrue) + .help("Produce no output when the input is empty.") + .long_help( + "When this flag is set, bat will produce no output at all when \ + the input is empty. This is useful when piping commands that may \ + produce empty output, like 'git diff'.", + ), + ) .arg( Arg::new("acknowledgements") .long("acknowledgements") From 6f0a61cef962c203031f83f0a3e1275598d5a7f6 Mon Sep 17 00:00:00 2001 From: dddffgg Date: Sat, 31 Jan 2026 16:41:46 +0800 Subject: [PATCH 03/16] feat: wire up quiet_empty config in app --- src/bin/bat/app.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 1ba3e73d..f5f59ec7 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -461,6 +461,7 @@ impl App { Some("auto") => StripAnsiMode::Auto, _ => unreachable!("other values for --strip-ansi are not allowed"), }, + quiet_empty: self.matches.get_flag("quiet-empty"), theme: theme(self.theme_options()).to_string(), visible_lines: match self.matches.try_contains_id("diff").unwrap_or_default() && self.matches.get_flag("diff") From 783acbc83dda26c14b99aa0d2fa3eb0d08305825 Mon Sep 17 00:00:00 2001 From: dddffgg Date: Sat, 31 Jan 2026 16:42:28 +0800 Subject: [PATCH 04/16] feat: implement quiet_empty behavior in printer --- src/printer.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/printer.rs b/src/printer.rs index 1ddd5e66..3c3facf5 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -454,6 +454,11 @@ impl Printer for InteractivePrinter<'_> { input: &OpenedInput, add_header_padding: bool, ) -> Result<()> { + // If input is empty and quiet_empty is enabled, skip all output + if self.content_type.is_none() && self.config.quiet_empty { + return Ok(()); + } + if add_header_padding && self.config.style_components.rule() { self.print_horizontal_line_term(handle, self.colors.rule)?; } @@ -556,6 +561,11 @@ impl Printer for InteractivePrinter<'_> { } fn print_footer(&mut self, handle: &mut OutputHandle, _input: &OpenedInput) -> Result<()> { + // If input is empty and quiet_empty is enabled, skip footer + if self.content_type.is_none() && self.config.quiet_empty { + return Ok(()); + } + if self.config.style_components.grid() && (self.content_type.is_some_and(|c| c.is_text()) || self.config.show_nonprintable From 26118afde0ad5459db4e7b61c0d91739f84726e1 Mon Sep 17 00:00:00 2001 From: dddffgg Date: Sat, 31 Jan 2026 16:44:39 +0800 Subject: [PATCH 05/16] docs: add changelog entry for --quiet-empty flag --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6e1ae81..f9e1c525 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ## Features +- Add `--quiet-empty` (`-E`) flag to suppress output when input is empty, see #1936 (@NORMAL-EX) - Improve native man pages and command help syntax highlighting by stripping overstriking, see #3517 (@akirk) ## Bugfixes From 6a7936a26fa8e941d9fe3035dbae596b2dd57991 Mon Sep 17 00:00:00 2001 From: dddffgg Date: Sat, 31 Jan 2026 16:45:46 +0800 Subject: [PATCH 06/16] test: add integration tests for --quiet-empty flag --- tests/integration_tests.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 250b3d2e..7b4e2df4 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -3654,3 +3654,33 @@ fn plain_with_sized_terminal_width() { .stdout("hello \nworld\n") .stderr(""); } + +#[test] +fn quiet_empty_suppresses_output_on_empty_stdin() { + bat() + .arg("--quiet-empty") + .write_stdin("") + .assert() + .success() + .stdout(""); +} + +#[test] +fn quiet_empty_does_not_affect_non_empty_input() { + bat() + .arg("--quiet-empty") + .write_stdin("hello\n") + .assert() + .success() + .stdout("hello\n"); +} + +#[test] +fn quiet_empty_suppresses_output_on_empty_file() { + bat() + .arg("--quiet-empty") + .arg("empty.txt") + .assert() + .success() + .stdout(""); +} From edb8342eab8eaae3b467b1657b49168ac0f58771 Mon Sep 17 00:00:00 2001 From: dddffgg Date: Sat, 31 Jan 2026 16:48:03 +0800 Subject: [PATCH 07/16] docs: fix changelog entry to reference PR number --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9e1c525..9934329f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ## Features -- Add `--quiet-empty` (`-E`) flag to suppress output when input is empty, see #1936 (@NORMAL-EX) +- Add `--quiet-empty` (`-E`) flag to suppress output when input is empty. Closes #1936, see #3563 (@NORMAL-EX) - Improve native man pages and command help syntax highlighting by stripping overstriking, see #3517 (@akirk) ## Bugfixes From 2030ffa66426cc0e0c65b5df44f4d944a8875491 Mon Sep 17 00:00:00 2001 From: dddffgg Date: Sat, 31 Jan 2026 17:02:12 +0800 Subject: [PATCH 08/16] docs: update short-help.txt with --quiet-empty flag --- doc/short-help.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/short-help.txt b/doc/short-help.txt index d67a51d0..3c58a057 100644 --- a/doc/short-help.txt +++ b/doc/short-help.txt @@ -23,6 +23,8 @@ Options: Specify the name to display for a file. -d, --diff Only show lines that have been added/removed/modified. + -E, --quiet-empty + Produce no output when the input is empty. --tabs Set the tab width to T spaces. --wrap From 3aaec8cb3ba3c7187933d5b243ef35188955d312 Mon Sep 17 00:00:00 2001 From: dddffgg Date: Sat, 31 Jan 2026 17:02:24 +0800 Subject: [PATCH 09/16] docs: update long-help.txt with --quiet-empty flag --- doc/long-help.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/long-help.txt b/doc/long-help.txt index 8cb60812..023fa593 100644 --- a/doc/long-help.txt +++ b/doc/long-help.txt @@ -57,6 +57,10 @@ Options: --diff-context Include N lines of context around added/removed/modified lines when using '--diff'. + -E, --quiet-empty + When this flag is set, bat will produce no output at all when the input is empty. This is + useful when piping commands that may produce empty output, like 'git diff'. + --tabs Set the tab width to T spaces. Use a width of 0 to pass tabs through directly From cb83b8fb9a4077b3235c67d9babf209c92114429 Mon Sep 17 00:00:00 2001 From: dddffgg Date: Sun, 1 Feb 2026 11:47:24 +0800 Subject: [PATCH 10/16] fix: correct position of --quiet-empty in short-help.txt --- doc/short-help.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/short-help.txt b/doc/short-help.txt index 3c58a057..41a0fdee 100644 --- a/doc/short-help.txt +++ b/doc/short-help.txt @@ -23,8 +23,6 @@ Options: Specify the name to display for a file. -d, --diff Only show lines that have been added/removed/modified. - -E, --quiet-empty - Produce no output when the input is empty. --tabs Set the tab width to T spaces. --wrap @@ -62,6 +60,8 @@ Options: Display all supported languages. --completion Show shell completion for a certain shell. [possible values: bash, fish, zsh, ps1] + -E, --quiet-empty + Produce no output when the input is empty. -h, --help Print help (see more with '--help') -V, --version From fa66d8e3efaa0760ab1a2800471659c6e19c769b Mon Sep 17 00:00:00 2001 From: dddffgg Date: Sun, 1 Feb 2026 11:48:10 +0800 Subject: [PATCH 11/16] fix: correct position of --quiet-empty in long-help.txt --- doc/long-help.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/long-help.txt b/doc/long-help.txt index 023fa593..994a3810 100644 --- a/doc/long-help.txt +++ b/doc/long-help.txt @@ -57,10 +57,6 @@ Options: --diff-context Include N lines of context around added/removed/modified lines when using '--diff'. - -E, --quiet-empty - When this flag is set, bat will produce no output at all when the input is empty. This is - useful when piping commands that may produce empty output, like 'git diff'. - --tabs Set the tab width to T spaces. Use a width of 0 to pass tabs through directly @@ -216,6 +212,10 @@ Options: --diagnostic Show diagnostic information for bug reports. + -E, --quiet-empty + When this flag is set, bat will produce no output at all when the input is empty. This is + useful when piping commands that may produce empty output, like 'git diff'. + --acknowledgements Show acknowledgements. From 55306c15a6dbde159fea5cc66d048b2d2f7bd283 Mon Sep 17 00:00:00 2001 From: dddffgg Date: Sun, 1 Feb 2026 16:20:27 +0800 Subject: [PATCH 12/16] docs: add --quiet-empty to man page --- assets/manual/bat.1.in | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/assets/manual/bat.1.in b/assets/manual/bat.1.in index 0be4bb63..ff4cb76f 100644 --- a/assets/manual/bat.1.in +++ b/assets/manual/bat.1.in @@ -282,6 +282,10 @@ Show bat's cache directory. .IP Show diagnostic information for bug reports. .HP +\fB\-\-quiet\-empty\fR +.IP +Do not produce any output when the input is empty (e.g. an empty file or empty stdin). This is useful in scripts where silent behavior is preferred for empty input. +.HP \fB\-\-acknowledgements\fR .IP Show acknowledgements. From bd461afd753b1a08a05696a75f7acdcd6bea04fb Mon Sep 17 00:00:00 2001 From: dddffgg Date: Sun, 1 Feb 2026 16:20:49 +0800 Subject: [PATCH 13/16] docs: add --quiet-empty to bash completion --- assets/completions/bat.bash.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/assets/completions/bat.bash.in b/assets/completions/bat.bash.in index 66be3985..7593df8f 100644 --- a/assets/completions/bat.bash.in +++ b/assets/completions/bat.bash.in @@ -100,6 +100,7 @@ _bat() { --lessopen | \ --no-paging | \ --diagnostic | \ + --quiet-empty | \ --acknowledgements | \ -h | --help | \ -V | --version | \ @@ -227,6 +228,7 @@ _bat() { --lessopen --completion --diagnostic + --quiet-empty --acknowledgements --set-terminal-title --help From 93411a96e4c37f164b87b123774c6c9b447021e4 Mon Sep 17 00:00:00 2001 From: dddffgg Date: Sun, 1 Feb 2026 16:21:05 +0800 Subject: [PATCH 14/16] docs: add --quiet-empty to zsh completion --- assets/completions/bat.zsh.in | 1 + 1 file changed, 1 insertion(+) diff --git a/assets/completions/bat.zsh.in b/assets/completions/bat.zsh.in index 910ec9d0..da9a66e6 100644 --- a/assets/completions/bat.zsh.in +++ b/assets/completions/bat.zsh.in @@ -62,6 +62,7 @@ _{{PROJECT_EXECUTABLE}}_main() { --completion='[show shell completion for a certain shell]:shell:(bash fish zsh ps1)' --set-terminal-title'[sets terminal title to filenames when using a pager]' --diagnostic'[show diagnostic information for bug reports]' + --quiet-empty'[do not produce any output when the input is empty]' -P'[disable paging]' "--no-config[don't use the configuration file]" "--no-custom-assets[don't load custom assets]" From 9a5519057cb8ad3e92fc761c090e968c925a68ee Mon Sep 17 00:00:00 2001 From: dddffgg Date: Sun, 1 Feb 2026 16:21:22 +0800 Subject: [PATCH 15/16] docs: add --quiet-empty to fish completion --- assets/completions/bat.fish.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/assets/completions/bat.fish.in b/assets/completions/bat.fish.in index 09f6407b..21c07adf 100644 --- a/assets/completions/bat.fish.in +++ b/assets/completions/bat.fish.in @@ -61,7 +61,7 @@ function __bat_no_excl_args -s V -l version \ -l acknowledgements \ -l config-dir -l config-file \ - -l diagnostic \ + -l diagnostic -l quiet-empty \ -l list-languages -l list-themes end @@ -159,6 +159,7 @@ complete -c $bat -l config-file -f -d "Display location of configuration file" - complete -c $bat -l decorations -x -a "$decorations_opts" -d "When to use --style decorations" -n __bat_no_excl_args complete -c $bat -l diagnostic -d "Print diagnostic info for bug reports" -n __fish_is_first_arg +complete -c $bat -l quiet-empty -d "Do not produce any output when the input is empty" -n __fish_is_first_arg complete -c $bat -s d -l diff -d "Only show lines with Git changes" -n __bat_no_excl_args From 3b34b47d5555e52189abd77b508e4b29d3b84a08 Mon Sep 17 00:00:00 2001 From: dddffgg Date: Sun, 1 Feb 2026 16:21:38 +0800 Subject: [PATCH 16/16] docs: add --quiet-empty to PowerShell completion --- assets/completions/_bat.ps1.in | 1 + 1 file changed, 1 insertion(+) diff --git a/assets/completions/_bat.ps1.in b/assets/completions/_bat.ps1.in index a9b3bcd5..db10302a 100644 --- a/assets/completions/_bat.ps1.in +++ b/assets/completions/_bat.ps1.in @@ -186,6 +186,7 @@ Register-ArgumentCompleter -Native -CommandName '{{PROJECT_EXECUTABLE}}' -Script [CompletionResult]::new('--acknowledgements' , 'acknowledgements' , [CompletionResultType]::ParameterName, 'Show acknowledgements.') [CompletionResult]::new('--set-terminal-title' , 'set-terminal-title' , [CompletionResultType]::ParameterName, 'Sets terminal title to filenames when using a pager.') [CompletionResult]::new('--diagnostic' , 'diagnostic' , [CompletionResultType]::ParameterName, 'Show diagnostic information for bug reports.') + [CompletionResult]::new('--quiet-empty' , 'quiet-empty' , [CompletionResultType]::ParameterName, 'Do not produce any output when the input is empty.') # [CompletionResult]::new('-h' , 'h' , [CompletionResultType]::ParameterName, 'Print this help message.') [CompletionResult]::new('--help' , 'help' , [CompletionResultType]::ParameterName, 'Print this help message.') # [CompletionResult]::new('-V' , 'V' , [CompletionResultType]::ParameterName, 'Show version information.')