From d9dd9729b8635f8ce657e0617ed5c3e4bf724a1d Mon Sep 17 00:00:00 2001 From: Eric Menne Date: Fri, 15 Aug 2025 15:44:09 +0200 Subject: [PATCH 1/3] Add flag to less to enable quitting on Ctrl-C --- src/output.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/output.rs b/src/output.rs index bb9a45d5..29c4ac64 100644 --- a/src/output.rs +++ b/src/output.rs @@ -93,6 +93,9 @@ impl OutputType { p.arg("-S"); // Short version of --chop-long-lines for compatibility } + // Ensures that 'less' quits together with 'bat' + p.arg("-K"); // Sort 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. // From 3d174b8c09f6cddcbb857d5aa64f086df53b612f Mon Sep 17 00:00:00 2001 From: Eric Menne Date: Fri, 15 Aug 2025 15:50:16 +0200 Subject: [PATCH 2/3] Updated README.md to include -K option for less --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index efb4dd65..cccba463 100644 --- a/README.md +++ b/README.md @@ -646,7 +646,7 @@ If you want to pass command-line arguments to the pager, you can also set them v `PAGER`/`BAT_PAGER` variables: ```bash -export BAT_PAGER="less -RF" +export BAT_PAGER="less -RFK" ``` Instead of using environment variables, you can also use `bat`'s [configuration file](#configuration-file) to configure the pager (`--pager` option). @@ -656,7 +656,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` to improve the experience. Specifically, `-R`/`--RAW-CONTROL-CHARS`, `-F`/`--quit-if-one-screen`, -and under certain conditions, `-X`/`--no-init` and/or `-S`/`--chop-long-lines`. +`-K`/`--quit-on-intr` and under certain conditions, `-X`/`--no-init` and/or `-S`/`--chop-long-lines`. >[!IMPORTANT] > These options will not be added if: @@ -674,6 +674,9 @@ The `-F` option instructs `less` to exit immediately if the output size is small the vertical size of the terminal. This is convenient for small files because you do not have to press `q` to quit the pager. +The `-K` option instructs `less` to exit immediately when an interrupt character is received. +This is useful to ensure that `less` quits together with `bat` on interrupt characters. + The `-X` option is needed to fix a bug with the `--quit-if-one-screen` feature in versions of `less` older than version 530. 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 From d397bea6dc110f8ccd30a288b70d39a8e7ddf6f6 Mon Sep 17 00:00:00 2001 From: Eric Menne Date: Sat, 16 Aug 2025 15:23:35 +0200 Subject: [PATCH 3/3] Fix typo and clarify description --- README.md | 4 ++-- src/output.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cccba463..413a8a84 100644 --- a/README.md +++ b/README.md @@ -674,8 +674,8 @@ The `-F` option instructs `less` to exit immediately if the output size is small the vertical size of the terminal. This is convenient for small files because you do not have to press `q` to quit the pager. -The `-K` option instructs `less` to exit immediately when an interrupt character is received. -This is useful to ensure that `less` quits together with `bat` on interrupt characters. +The `-K` 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. The `-X` option is needed to fix a bug with the `--quit-if-one-screen` feature in versions of `less` older than version 530. Unfortunately, it also breaks mouse-wheel support in `less`. diff --git a/src/output.rs b/src/output.rs index 29c4ac64..e15c478e 100644 --- a/src/output.rs +++ b/src/output.rs @@ -94,7 +94,7 @@ impl OutputType { } // Ensures that 'less' quits together with 'bat' - p.arg("-K"); // Sort version of ' --quit-on-intr' + 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.