From f874c8e4dbb13defbb842398853cdea8e23e39d9 Mon Sep 17 00:00:00 2001 From: Ethan P Date: Sun, 10 Jan 2021 13:57:05 -0800 Subject: [PATCH] Use less binary specified in bat config for --diagnostic --- src/bin/bat/main.rs | 4 +++- src/config.rs | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index 13d5ddb5..1d430c30 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -229,6 +229,8 @@ fn run() -> Result { if app.matches.is_present("diagnostic") { use bugreport::{bugreport, collector::*, format::Markdown}; + let pager = bat::config::get_pager_executable(app.matches.value_of("pager")) + .unwrap_or("less".to_owned()); // FIXME: Avoid non-canonical path to "less". bugreport!() .info(SoftwareVersion::default()) @@ -252,7 +254,7 @@ fn run() -> Result { ])) .info(FileContent::new("Config file", config_file())) .info(CompileTimeInformation::default()) - .info(CommandOutput::new("Less version", "less", &["--version"])) + .info(CommandOutput::new("Less version", pager, &["--version"])) .print::(); return Ok(true); diff --git a/src/config.rs b/src/config.rs index 58d30a3b..6bb84ab9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -84,6 +84,15 @@ pub struct Config<'a> { pub highlighted_lines: HighlightedLineRanges, } +#[cfg(all(feature = "application", feature = "paging"))] +pub fn get_pager_executable(config_pager: Option<&str>) -> Option { + if let Ok(Some(pager)) = crate::pager::get_pager(config_pager) { + Some(pager.bin) + } else { + None + } +} + #[test] fn default_config_should_include_all_lines() { use crate::line_range::RangeCheckResult;