Skip to content

Add environment variable BAT_PAGING#2641

Merged
Enselic merged 2 commits intosharkdp:masterfrom
einfachIrgendwer0815:feature_bat_paging_env
Sep 1, 2023
Merged

Add environment variable BAT_PAGING#2641
Enselic merged 2 commits intosharkdp:masterfrom
einfachIrgendwer0815:feature_bat_paging_env

Conversation

@einfachIrgendwer0815
Copy link
Copy Markdown
Contributor

Fixes #2629

@Enselic
Copy link
Copy Markdown
Collaborator

Enselic commented Aug 6, 2023

Thank you for the PR!

I'm tempted to approve this because of how straightforward and symmetrical it is.

But I don't quite understand what is wrong with the existing method to disable that pager with an env var: BAT_PAGER= bat some-long-file.txt. Could you explain a bit more perhaps?

@einfachIrgendwer0815
Copy link
Copy Markdown
Contributor Author

I think setting BAT_PAGER='' to disable paging is a somewhat indirect way of doing so. If you want to disable paging, you want to change the paging behaviour. But by using BAT_PAGER you are actually changing which pager to use. So, correct me if I'm wrong, you're basically saying to bat, "Do paging, but without a pager" which in turn forces bat not to use paging. So BAT_PAGER kind of controls two options here. But saying, "Don't do paging" by setting BAT_PAGING=never would make the intent clearer.

In addition, it is currently not possible to set BAT_PAGER='' to disable paging, but at the same time set a pager to use in case you exceptionally want paging. If there was BAT_PAGING, you could set BAT_PAGING=never to disable paging in general. But you could also set BAT_PAGER to the pager you want when exceptionally using paging. Then when using bat --paging=always, bat would use the pager set by BAT_PAGER.

Also, BAT_PAGING=always allows to set --paging always in the environment, which is currently not possible.

@Enselic
Copy link
Copy Markdown
Collaborator

Enselic commented Aug 6, 2023

Makes sense! Would be great if you could a simple regression test for this change. A test that runs with BAT_BAGER set but uses BAT_PAGING=never to disable it. The regression test should fail without the fix. Thanks!

@einfachIrgendwer0815
Copy link
Copy Markdown
Contributor Author

I have just come across this:

pub fn bat_raw_command_with_config() -> Command {
let mut cmd = Command::cargo_bin("bat").unwrap();
cmd.current_dir("tests/examples");
cmd.env_remove("BAT_CACHE_PATH");
cmd.env_remove("BAT_CONFIG_DIR");
cmd.env_remove("BAT_CONFIG_PATH");
cmd.env_remove("BAT_OPTS");
cmd.env_remove("BAT_PAGER");
cmd.env_remove("BAT_STYLE");
cmd.env_remove("BAT_TABS");
cmd.env_remove("BAT_THEME");
cmd.env_remove("COLORTERM");
cmd.env_remove("NO_COLOR");
cmd.env_remove("PAGER");
cmd
}

# Clean up environment
unset BAT_CACHE_PATH
unset BAT_CONFIG_DIR
unset BAT_CONFIG_PATH
unset BAT_OPTS
unset BAT_PAGER
unset BAT_STYLE
unset BAT_TABS
unset BAT_THEME
unset COLORTERM
unset NO_COLOR
unset PAGER

def create_highlighted_version(args):
output_basepath, source = args
env = os.environ.copy()
env.pop("BAT_CACHE_PATH", None)
env.pop("BAT_CONFIG_DIR", None)
env.pop("BAT_CONFIG_PATH", None)
env.pop("BAT_OPTS", None)
env.pop("BAT_PAGER", None)
env.pop("BAT_STYLE", None)
env.pop("BAT_TABS", None)
env.pop("BAT_THEME", None)
env.pop("NO_COLOR", None)
env.pop("PAGER", None)

Should BAT_PAGING be added?

@Enselic
Copy link
Copy Markdown
Collaborator

Enselic commented Aug 6, 2023

You'll want to add a test to https://github.com/sharkdp/bat/blob/master/tests/integration_tests.rs, search for BAT_PAGER in that file

@einfachIrgendwer0815
Copy link
Copy Markdown
Contributor Author

einfachIrgendwer0815 commented Aug 7, 2023

Makes sense! Would be great if you could a simple regression test for this change. A test that runs with BAT_BAGER set but uses BAT_PAGING=never to disable it. The regression test should fail without the fix. Thanks!

Unfortunately, that test doesn't fail without the fix applied because the tests don't run bat on an interactive terminal, which means the default is no paging, so setting BAT_PAGING=never wouldn't change anything.

So instead the test I wrote sets BAT_PAGING=always to make sure BAT_PAGING actually has an effect.

@Enselic
Copy link
Copy Markdown
Collaborator

Enselic commented Sep 1, 2023

Thank you for the effort. Let's merge.

@Enselic Enselic merged commit 4b04f90 into sharkdp:master Sep 1, 2023
@einfachIrgendwer0815 einfachIrgendwer0815 deleted the feature_bat_paging_env branch February 24, 2024 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug?: disabling paging is impossible without overriding the pager

2 participants