From 67fe833bc87d88ebb395be4a2d1c1d9806812c13 Mon Sep 17 00:00:00 2001 From: Morten Linderud Date: Fri, 12 Oct 2018 17:37:57 +0200 Subject: [PATCH] Add arguments from PAGER/BAT_PAGER Solves #352 Signed-off-by: Morten Linderud --- src/output.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/output.rs b/src/output.rs index d8bfa5f5..3c11914a 100644 --- a/src/output.rs +++ b/src/output.rs @@ -1,3 +1,5 @@ +extern crate shell_words; + use std::env; use std::ffi::OsString; use std::io::{self, Write}; @@ -28,23 +30,27 @@ impl OutputType { .or_else(|_| env::var("PAGER")) .unwrap_or(String::from("less")); - let less_path = PathBuf::from(&pager); + let pagerflags = shell_words::split(&pager).unwrap_or(vec![pager]); + + let less_path = PathBuf::from(&pagerflags[0]); let is_less = less_path.file_stem() == Some(&OsString::from("less")); let mut process = if is_less { - let mut args = vec!["--RAW-CONTROL-CHARS", "--no-init"]; - if quit_if_one_screen { - args.push("--quit-if-one-screen"); - } - let mut p = Command::new(&less_path); - p.args(&args).env("LESSCHARSET", "UTF-8"); + if pagerflags.len() == 1 { + p.args(vec!["--RAW-CONTROL-CHARS", "--no-init"]); + if quit_if_one_screen { + p.arg("--quit-if-one-screen"); + } + } + p.env("LESSCHARSET", "UTF-8"); p } else { - Command::new(pager) + Command::new(&less_path) }; process + .args(&pagerflags[1..]) .stdin(Stdio::piped()) .spawn() .map(OutputType::Pager)