-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not parse arguments in PAGER #454
Conversation
@sharkdp I am struggling with fixing the test case bat/tests/integration_tests.rs Line 313 in b68c5d8
|
I tried by creating pager_output.sh file, but the windows test failed. :( |
Thank you very much for looking into this! Maybe we could do the following (this would also fix the
This way, if someone wants to use |
Thanks. I'll try it. |
6ecada6
to
533a3e5
Compare
src/output.rs
Outdated
@@ -26,7 +26,8 @@ impl OutputType { | |||
|
|||
/// Try to launch the pager. Fall back to stdout in case of errors. | |||
fn try_pager(quit_if_one_screen: bool, pager_from_config: Option<&str>) -> Result<Self> { | |||
let pager_from_env = env::var("BAT_PAGER").or_else(|_| env::var("PAGER")); | |||
let pager_from_env = | |||
env::var("BAT_PAGER").or_else(|_| env::var("PAGER").map(add_default_flags_to_less)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole point of this was to have a different handling of PAGER
and BAT_PAGER
. We do not want to modify anything for BAT_PAGER
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
env::var("BAT_PAGER")
is not modified. Only env::var("pager")
is mapped by the function add_default_flags_to_less
If I am misunderstanding your comment, please say freely about it.
src/output.rs
Outdated
// BAT_PAGER. | ||
fn add_default_flags_to_less(pager: String) -> String { | ||
if let Ok(flags) = shell_words::split(&pager) { | ||
if flags.first() == Some(&String::from("less")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not work if the first argument is /usr/bin/less
, for example. See the is_less
variable example in the same file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I missed it. I'll fix it now!
533a3e5
to
3a62f1f
Compare
3a62f1f
to
3547eff
Compare
When I run the same test in my repository, the test succeeded. I don't know why the test failed. Could you help me? |
@sharkdp Thanks! the test passed. Could you review this PR again? |
Yes, sorry for the delay. I'll do a final review soon. |
I don't really like the duplication of the logic here. We already have a piece of code that adds the default arguments in a specific way: Lines 52 to 57 in abf0229
We should strive to reuse that part of the code. |
@sharkdp Sorry for late. Then how about this? let pager_from_env = match (env::var("BAT_PAGER"), env::var("PAGER")) {
(Ok(bat_pager), _) => Some(bat_pager),
(_, Ok(pager)) => {
if PathBuf::from(pager.clone()).file_stem() == Some(&OsString::from("less")) {
Some(String::from("less"))
} else {
Some(pager)
}
}
_ => None,
}; If the |
This wouldn't work if In any case, thank you very much for your work and your patience. |
This fixes #430