Avoid endless bat executions with PAGER="bat"

From issue #383
This commit is contained in:
Rodrigo Orem 2018-10-31 20:22:56 -03:00 committed by David Peter
parent bc21c4d0e0
commit 8a0c30b385

View File

@ -27,11 +27,16 @@ impl OutputType {
/// Try to launch the pager. Fall back to stdout in case of errors. /// 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> { 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"));
let pager = pager_from_config
let mut pager = pager_from_config
.map(|p| p.to_string()) .map(|p| p.to_string())
.or(pager_from_env.ok()) .or(pager_from_env.ok())
.unwrap_or(String::from("less")); .unwrap_or(String::from("less"));
if pager == "bat" {
pager = String::from("less");
}
let pagerflags = shell_words::split(&pager) let pagerflags = shell_words::split(&pager)
.chain_err(|| "Could not parse (BAT_)PAGER environment variable.")?; .chain_err(|| "Could not parse (BAT_)PAGER environment variable.")?;