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 8aa9bce
Show file tree
Hide file tree
Showing 2 changed files with 10 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
2 changes: 2 additions & 0 deletions src/windows.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{ffi::OsStr, io, process::Command};

use crate::{CommandExt, IntoResult};

pub fn command<T: AsRef<OsStr>>(path: T) -> Command {
let mut cmd = Command::new("cmd");
cmd.arg("/c").arg("start").arg(path.as_ref());
Expand Down

0 comments on commit 8aa9bce

Please sign in to comment.