mirror of
https://github.com/chmln/handlr.git
synced 2025-03-16 02:15:54 +01:00
Run 'open' subcommand when handlr is invoked as xdg-open
This allows to simply symlink handlr to /usr/bin/xdg-open - no wrapper script is needed.
This commit is contained in:
parent
b9b71369f8
commit
28a5e67de7
1 changed files with 16 additions and 1 deletions
17
src/main.rs
17
src/main.rs
|
@ -1,6 +1,11 @@
|
|||
use config::CONFIG;
|
||||
use error::{Error, Result};
|
||||
use once_cell::sync::Lazy;
|
||||
use std::{
|
||||
ffi::OsStr,
|
||||
ffi::OsString,
|
||||
path::Path,
|
||||
};
|
||||
|
||||
mod apps;
|
||||
mod cli;
|
||||
|
@ -20,8 +25,18 @@ fn main() -> Result<()> {
|
|||
|
||||
let mut apps = (*apps::APPS).clone();
|
||||
|
||||
let mut args = std::env::args_os().collect::<Vec<OsString>>();
|
||||
let cmd_name = Path::new(&args[0]).file_stem();
|
||||
|
||||
// If the program is invoked with name `xdg-open` (via symlink xdg-open -> handlr),
|
||||
// rewrite arguments to `handlr open ...`.
|
||||
if cmd_name == Some(OsStr::new("xdg-open")) {
|
||||
args[0] = clap::crate_name!().into(); // fix program name in help message
|
||||
args.insert(1, "open".into());
|
||||
}
|
||||
|
||||
let res = || -> Result<()> {
|
||||
match Cmd::parse() {
|
||||
match Cmd::parse_from(args) {
|
||||
Cmd::Set { mime, handler } => {
|
||||
apps.set_handler(mime.0, handler);
|
||||
apps.save()?;
|
||||
|
|
Loading…
Add table
Reference in a new issue