Pass -+J to less to turn off the status column

With -J in $LESS, less draws a status column two characters wide on
the left, so lines that bat already wrapped to the terminal width wrap
a second time and the rest of them ends up over the line numbers.

Reset the option with -+J next to the other default less arguments and
skip it for BusyBox less like -K, since it does not support it either.
+J does not work here, less runs it as the J command on startup.

Closes #2497
This commit is contained in:
dualfroz committed 2026-10-18 13:22:24 +02:00
1 parent fcaf1acdc8
commit daa163bc7d
5 files changed
+28 -1

No files matched your search

+1
View File
@@ -25,6 +25,7 @@
- Syntax highlighting for Python files using uv as script runner in shebang #3689 (@janlarres) - Syntax highlighting for Python files using uv as script runner in shebang #3689 (@janlarres)
## Bugfixes ## Bugfixes
- Turn off the `less` status column (`-J`, e.g. from `$LESS`) so wrapped lines no longer overlap the line numbers, closes #2497, see #4085 (@dualfroz)
- Exit quietly with status 0 instead of panicking when stdout is closed early (broken pipe) on auxiliary output paths such as `--completion`, `--config-file`, `--diagnostic`, `--generate-config-file`, `--set-terminal-title` and `cache --build`/`--clear`, matching the main output path since #232, closes #4034, see #4035 (@Mathjk) - Exit quietly with status 0 instead of panicking when stdout is closed early (broken pipe) on auxiliary output paths such as `--completion`, `--config-file`, `--diagnostic`, `--generate-config-file`, `--set-terminal-title` and `cache --build`/`--clear`, matching the main output path since #232, closes #4034, see #4035 (@Mathjk)
- Track strikethrough (SGR 9 / 29) in the ANSI style tracker so it is re-emitted like bold, dim, italic, and underline, and is no longer dropped after the first highlighted token when displaying ANSI input with syntax highlighting, see #4015 (@mikehasa) - Track strikethrough (SGR 9 / 29) in the ANSI style tracker so it is re-emitted like bold, dim, italic, and underline, and is no longer dropped after the first highlighted token when displaying ANSI input with syntax highlighting, see #4015 (@mikehasa)
- Allow boolean flags to be given more than once, so that a flag set in the config file can also be passed on the command line without erroring, see #3912 (@logarithmone1128) - Allow boolean flags to be given more than once, so that a flag set in the config file can also be passed on the command line without erroring, see #3912 (@logarithmone1128)
+4 -1
View File
@@ -666,7 +666,7 @@ Instead of using environment variables, you can also use `bat`'s [configuration
When using `less` as a pager, `bat` will automatically pass extra options along to `less` When using `less` as a pager, `bat` will automatically pass extra options along to `less`
to improve the experience. Specifically, `-R`/`--RAW-CONTROL-CHARS`, `-F`/`--quit-if-one-screen`, to improve the experience. Specifically, `-R`/`--RAW-CONTROL-CHARS`, `-F`/`--quit-if-one-screen`,
`-K`/`--quit-on-intr` and under certain conditions, `-X`/`--no-init` and/or `-S`/`--chop-long-lines`. `-K`/`--quit-on-intr`, `-+J` and under certain conditions, `-X`/`--no-init` and/or `-S`/`--chop-long-lines`.
>[!IMPORTANT] >[!IMPORTANT]
> These options will not be added if: > These options will not be added if:
@@ -687,6 +687,9 @@ have to press `q` to quit the pager.
The `-K`/`--quit-on-intr` option instructs `less` to exit immediately when an interrupt signal is received. The `-K`/`--quit-on-intr` option instructs `less` to exit immediately when an interrupt signal is received.
This is useful to ensure that `less` quits together with `bat` on SIGINT. This is useful to ensure that `less` quits together with `bat` on SIGINT.
The `-+J` option turns off the `-J`/`--status-column` option, e.g. when it is set in the `LESS` environment variable.
The status column takes up two columns, so lines that `bat` already wrapped to the terminal width would wrap again.
The `-X`/`--no-init` option is added to versions of `less` older than version 530 (older than 558 on Windows) to The `-X`/`--no-init` option is added to versions of `less` older than version 530 (older than 558 on Windows) to
fix a bug with the `-F`/`--quit-if-one-screen` feature. Unfortunately, it also breaks mouse-wheel support in `less`. fix a bug with the `-F`/`--quit-if-one-screen` feature. Unfortunately, it also breaks mouse-wheel support in `less`.
If you want to enable mouse-wheel scrolling on older versions of `less` and do not mind losing If you want to enable mouse-wheel scrolling on older versions of `less` and do not mind losing
+7
View File
@@ -155,6 +155,13 @@ impl OutputType {
p.arg("-K"); // Short version of '--quit-on-intr' p.arg("-K"); // Short version of '--quit-on-intr'
} }
// The status column ('-J', e.g. from $LESS) takes two columns away from
// lines that bat already wrapped to the terminal width, so turn it off.
// The BusyBox version of less does not support '-+'.
if less_version != Some(LessVersion::BusyBox) {
p.arg("-+J"); // Resets '--status-column' to its default
}
// Passing '--no-init' fixes a bug with '--quit-if-one-screen' in older // Passing '--no-init' fixes a bug with '--quit-if-one-screen' in older
// versions of 'less'. Unfortunately, it also breaks mouse-wheel support. // versions of 'less'. Unfortunately, it also breaks mouse-wheel support.
// //
+14
View File
@@ -1586,6 +1586,20 @@ fn pager_more() {
}); });
} }
/// The status column of less (-J, e.g. from $LESS) makes lines wrap onto
/// the decorations, so it has to be reset when bat builds the less arguments
#[test]
#[cfg(unix)]
fn pager_less_resets_status_column() {
bat()
.arg("--pager=../mocked-pagers/less.sh")
.arg("--paging=always")
.arg("test.txt")
.assert()
.success()
.stdout(predicate::str::contains("-+J"));
}
#[test] #[test]
fn alias_pager_disable() { fn alias_pager_disable() {
bat() bat()
+2
View File
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
echo "$@"