Skip to content

Commit

Permalink
Merge pull request #260 from tandetat/master
Browse files Browse the repository at this point in the history
check OS to use appropriate program to open files in rga-fzf
  • Loading branch information
phiresky authored Nov 26, 2024
2 parents b4dbe1b + 87c02bd commit 108eaea
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/bin/rga-fzf-open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ fn main() -> anyhow::Result<()> {
let query = args.next().context("no query")?;
let fname = args.next().context("no filename")?;
// let instance_id = std::env::var("RGA_FZF_INSTANCE").unwrap_or("unk".to_string());
use std::env;

let (cmd, pdf_cmd) = match env::consts::OS {
"macos" => ("open", "open -a Preview.app"), // use native Preview for macOs
"linux" => ("xdg-open", "evince"), // use evince for linux
&_ => ("", ""),
};
if fname.ends_with(".pdf") {
use std::io::ErrorKind::*;
let worked = Command::new("evince")
let worked = Command::new(pdf_cmd)
.arg("--find")
.arg(&query)
.arg(&fname)
Expand All @@ -29,7 +35,6 @@ fn main() -> anyhow::Result<()> {
return Ok(());
}
}
Command::new("xdg-open").arg(fname).spawn()?;

Command::new(cmd).arg(fname).spawn()?;
Ok(())
}

0 comments on commit 108eaea

Please sign in to comment.