Skip to content

Commit

Permalink
try commands without args
Browse files Browse the repository at this point in the history
  • Loading branch information
matoous committed Feb 5, 2023
1 parent fdd2ef0 commit d136c3a
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ use crate::{CommandExt, IntoResult};
pub fn command<T: AsRef<OsStr>>(path: T) -> Command {
let path = path.as_ref();
let open_handlers = [
("xdg-open", &["--version"], &[path] as &[_]),
("gio", &["version"], &[OsStr::new("open"), path]),
("gnome-open", &["--version"], &[path]),
("kde-open", &["--version"], &[path]),
("wslview", &["--version"], &[&wsl_path(path)]),
("xdg-open", &[path] as &[_]),
("gio", &[OsStr::new("open"), path]),
("gnome-open", &[path]),
("kde-open", &[path]),
("wslview", &[&wsl_path(path)]),
];

for (command, check_args, args) in &open_handlers {
let result = Command::new(command)
.args(*check_args)
.status_without_output();
for (command, args) in &open_handlers {
let result = Command::new(command).status_without_output();

if let Ok(status) = result {
if status.success() {
Expand All @@ -33,7 +31,7 @@ pub fn command<T: AsRef<OsStr>>(path: T) -> Command {
}

// fallback to xdg-open
let (command, _, args) = &open_handlers[0];
let (command, args) = &open_handlers[0];
let mut cmd = Command::new(command);
cmd.args(*args);
cmd
Expand Down

0 comments on commit d136c3a

Please sign in to comment.