From fca5502f21451fc40c1d1e7b26e76c8f549ad83f Mon Sep 17 00:00:00 2001 From: ANCHAL Date: Tue, 16 Dec 2025 22:25:27 +0530 Subject: [PATCH] Fix bat crash with BusyBox less on Windows - Retrieve less version earlier in src/output.rs. - Skip -K argument if less is detected as BusyBox version. - Reuses the version check for the existing --no-init logic. - Fixes #3518. --- CHANGELOG.md | 1 + src/output.rs | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ddefdcf5..720bb375 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Improve native man pages and command help syntax highlighting by stripping overstriking, see #3517 (@akirk) ## Bugfixes +- Fix crash with BusyBox `less` on Windows, see #3518 (@Anchal-T) - `--help` now correctly honors `--pager=builtin`. See #3516 (@keith-hall) - `--help` now correctly honors custom themes. See #3524 (@keith-hall) diff --git a/src/output.rs b/src/output.rs index 0926f2bf..6c728c4f 100644 --- a/src/output.rs +++ b/src/output.rs @@ -131,8 +131,13 @@ impl OutputType { p.arg("-S"); // Short version of --chop-long-lines for compatibility } + let less_version = retrieve_less_version(&pager.bin); + // Ensures that 'less' quits together with 'bat' - p.arg("-K"); // Short version of '--quit-on-intr' + // The BusyBox version of less does not support -K + if less_version != Some(LessVersion::BusyBox) { + p.arg("-K"); // Short version of '--quit-on-intr' + } // Passing '--no-init' fixes a bug with '--quit-if-one-screen' in older // versions of 'less'. Unfortunately, it also breaks mouse-wheel support. @@ -142,7 +147,7 @@ impl OutputType { // For newer versions (530 or 558 on Windows), we omit '--no-init' as it // is not needed anymore. if single_screen_action == SingleScreenAction::Quit { - match retrieve_less_version(&pager.bin) { + match less_version { None => { p.arg("--no-init"); }