From 76df41fa973a4fb1cd4192b0a5865b8c441cdf2c Mon Sep 17 00:00:00 2001 From: Aankhen Date: Thu, 6 Sep 2018 19:11:38 +0530 Subject: [PATCH] src/output.rs: Handle `less` in a portable way. --- src/output.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/output.rs b/src/output.rs index 8719c882..d8bfa5f5 100644 --- a/src/output.rs +++ b/src/output.rs @@ -1,5 +1,7 @@ use std::env; +use std::ffi::OsString; use std::io::{self, Write}; +use std::path::PathBuf; use std::process::{Child, Command, Stdio}; use app::PagingMode; @@ -26,13 +28,16 @@ impl OutputType { .or_else(|_| env::var("PAGER")) .unwrap_or(String::from("less")); - let mut process = if pager == "less" || pager.ends_with("/less") { + let less_path = PathBuf::from(&pager); + 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"); + let mut p = Command::new(&less_path); p.args(&args).env("LESSCHARSET", "UTF-8"); p } else {