Skip to content

Commit

Permalink
Merge pull request #31 from City-busz/patch-1
Browse files Browse the repository at this point in the history
Add support for gio open on Linux
  • Loading branch information
Byron authored Apr 18, 2021
2 parents ccbae5d + 6a1766a commit 10fd4a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $ open <path-or-url>
# Windows
$ start <path-or-url>
# Linux
$ open <path-or-url> || xdg-open <path-or-url> || gnome-open <path-or-url> || kde-open <path-or-url>
$ xdg-open <path-or-url> || gio open <path-or-url> || gnome-open <path-or-url> || kde-open <path-or-url> || wslview <path-or-url>
```

# Usage
Expand Down
24 changes: 17 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,28 @@ mod unix {
use which::which;

pub fn that<T: AsRef<OsStr> + Sized>(path: T) -> Result<ExitStatus> {
["xdg-open", "gnome-open", "kde-open", "wslview"] // Open handlers
["xdg-open", "gio", "gnome-open", "kde-open", "wslview"] // Open handlers
.iter()
.find(|it| which(it).is_ok()) // find the first handler that exists
.ok_or(Error::from_raw_os_error(0)) // If not found, return err
.and_then(|program| {
// If found run the handler
Command::new(program)
.stdout(Stdio::null())
.stderr(Stdio::null())
.arg(path.as_ref())
.spawn()?
.wait()
if *program == "gio" {
Command::new(program)
.stdout(Stdio::null())
.stderr(Stdio::null())
.arg("open")
.arg(path.as_ref())
.spawn()?
.wait()
} else {
Command::new(program)
.stdout(Stdio::null())
.stderr(Stdio::null())
.arg(path.as_ref())
.spawn()?
.wait()
}
})
}

Expand Down

0 comments on commit 10fd4a7

Please sign in to comment.