From 01fcbf2183e2f34152681036e2aedd1dc1ade2ed Mon Sep 17 00:00:00 2001 From: Rodrigo Orem <8618619+rodorgas@users.noreply.github.com> Date: Mon, 5 Nov 2018 18:41:51 -0200 Subject: [PATCH] Better placement of bat detection --- src/output.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/output.rs b/src/output.rs index c7a77758..7c007c00 100644 --- a/src/output.rs +++ b/src/output.rs @@ -28,20 +28,21 @@ impl OutputType { fn try_pager(quit_if_one_screen: bool, pager_from_config: Option<&str>) -> Result { let pager_from_env = env::var("BAT_PAGER").or_else(|_| env::var("PAGER")); - let mut pager = pager_from_config + let pager = pager_from_config .map(|p| p.to_string()) .or(pager_from_env.ok()) .unwrap_or(String::from("less")); - if pager == "bat" { - pager = String::from("less"); - } - let pagerflags = shell_words::split(&pager) .chain_err(|| "Could not parse (BAT_)PAGER environment variable.")?; match pagerflags.split_first() { - Some((pager_name, args)) => { + Some((initial_pager, args)) => { + let pager_name = match initial_pager.as_ref() { + "bat" => "less", + _ => initial_pager, + }; + let pager_path = PathBuf::from(pager_name); let is_less = pager_path.file_stem() == Some(&OsString::from("less"));