Repository: sharkdp/bat (language: rust)

Issue:
Bug?: disabling paging is impossible without overriding the pager
Currently, it is possible to disable paging in CLI via `bat --paging=never`. To make this configuration global, the help page / man pages suggest overriding the pager environment variable, `BAT_PAGER`. However, this behavior seems to be error-prone:

If `BAT_PAGER` is overridden, it is hard to "fix" it in CLI. Normally, env variables are overridden by CLI keys. E.g. with the standard CLI conventions, if you have `BAT_PAGING=never` and you'd run `bat --paging-never`, you'd get paging. With the current version of `bat` (`0.23.0 (871abd27)`), this is impossible.

This might be low-prio because I'm actually intending to set `bat` to non-paging mode by default and may not even switch back. I'm leaving this to the author's discretion. I'm also not sure if the issue is a "bug" (inconsistency with the standard CLI conventions), or simply a feature request. Triaging is welcomed

Thanks for the nice tool! :heart: 


Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b05bf87e9b..c7b672a217 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
 
 ## Features
 
+- Add environment variable `BAT_PAGING`, see #2629 (@einfachIrgendwer0815)
+
 ## Bugfixes
 
 ## Other
diff --git a/doc/long-help.txt b/doc/long-help.txt
index dafcfd7aca..247120fb5f 100644
--- a/doc/long-help.txt
+++ b/doc/long-help.txt
@@ -89,8 +89,8 @@ Options:
 
       --paging <when>
           Specify when to use the pager. To disable the pager, use --paging=never' or its
-          alias,'-P'. To disable the pager permanently, set BAT_PAGER to an empty string. To control
-          which pager is used, see the '--pager' option. Possible values: *auto*, never, always.
+          alias,'-P'. To disable the pager permanently, set BAT_PAGING to 'never'. To control which
+          pager is used, see the '--pager' option. Possible values: *auto*, never, always.
 
       --pager <command>
           Determine which pager is used. This option will override the PAGER and BAT_PAGER
diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs
index 2f63268624..acdd1d0891 100644
--- a/src/bin/bat/clap_app.rs
+++ b/src/bin/bat/clap_app.rs
@@ -311,7 +311,7 @@ pub fn build_app(interactive_output: bool) -> Command {
                 .long_help(
                     "Specify when to use the pager. To disable the pager, use \
                     --paging=never' or its alias,'-P'. To disable the pager permanently, \
-                    set BAT_PAGER to an empty string. To control which pager is used, see the \
+                    set BAT_PAGING to 'never'. To control which pager is used, see the \
                     '--pager' option. Possible values: *auto*, never, always."
                 ),
         )
diff --git a/src/bin/bat/config.rs b/src/bin/bat/config.rs
index 4abae4a69a..9e38dfa424 100644
--- a/src/bin/bat/config.rs
+++ b/src/bin/bat/config.rs
@@ -142,6 +142,7 @@ pub fn get_args_from_env_vars() -> Vec<OsString> {
         ("--tabs", "BAT_TABS"),
         ("--theme", "BAT_THEME"),
         ("--pager", "BAT_PAGER"),
+        ("--paging", "BAT_PAGING"),
         ("--style", "BAT_STYLE"),
     ]
     .iter()
diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs
index 65eb6f53ab..385140e6d1 100644
--- a/src/bin/bat/main.rs
+++ b/src/bin/bat/main.rs
@@ -255,6 +255,7 @@ fn invoke_bugreport(app: &App, cache_dir: &Path) {
             "LANG",
             "LC_ALL",
             "BAT_PAGER",
+            "BAT_PAGING",
             "BAT_CACHE_PATH",
             "BAT_CONFIG_PATH",
             "BAT_OPTS",


Test patch:
diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs
index 6194828036..d494d280bc 100644
--- a/tests/integration_tests.rs
+++ b/tests/integration_tests.rs
@@ -843,6 +843,17 @@ fn pager_failed_to_parse() {
         .stderr(predicate::str::contains("Could not parse pager command"));
 }
 
+#[test]
+fn env_var_bat_paging() {
+    bat()
+        .env("BAT_PAGER", "echo pager-output")
+        .env("BAT_PAGING", "always")
+        .arg("test.txt")
+        .assert()
+        .success()
+        .stdout(predicate::eq("pager-output\n"));
+}
+
 #[test]
 fn diagnostic_sanity_check() {
     bat()