Skip to content

Commit

Permalink
Add support for gio open on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
City-busz committed Apr 18, 2021
1 parent ccbae5d commit 90bc634
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.to_string() == "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 90bc634

Please sign in to comment.