mirror of
https://github.com/chmln/handlr.git
synced 2024-11-14 21:49:27 +01:00
add show command
This commit is contained in:
parent
90e78ba92d
commit
764b85f652
2 changed files with 30 additions and 0 deletions
|
@ -17,6 +17,12 @@ pub enum Cmd {
|
|||
paths: Vec<UserPath>,
|
||||
},
|
||||
|
||||
/// Show command to be executed by "open" command
|
||||
Show {
|
||||
#[clap(required = true)]
|
||||
paths: Vec<UserPath>,
|
||||
},
|
||||
|
||||
/// Set the default handler for mime/extension
|
||||
Set {
|
||||
mime: MimeOrExtension,
|
||||
|
|
24
src/main.rs
24
src/main.rs
|
@ -1,3 +1,5 @@
|
|||
use std::io::Write;
|
||||
|
||||
use config::CONFIG;
|
||||
use error::{Error, Result};
|
||||
use once_cell::sync::Lazy;
|
||||
|
@ -51,6 +53,28 @@ fn main() -> Result<()> {
|
|||
handler.open(paths)?;
|
||||
}
|
||||
}
|
||||
Cmd::Show { paths } => {
|
||||
let mut handlers: HashMap<Handler, Vec<String>> =
|
||||
HashMap::new();
|
||||
|
||||
for path in paths.into_iter() {
|
||||
handlers
|
||||
.entry(apps.get_handler(&path.get_mime()?.0)?)
|
||||
.or_default()
|
||||
.push(path.to_string());
|
||||
}
|
||||
|
||||
for (handler, paths) in handlers.into_iter() {
|
||||
let stdout = std::io::stdout();
|
||||
let (cmd, cmd_args) = handler.get_entry()?.get_cmd(paths)?;
|
||||
write!(&stdout, "{}", cmd)?;
|
||||
for arg in cmd_args.into_iter() {
|
||||
write!(&stdout, " {}", arg)?;
|
||||
}
|
||||
write!(&stdout, "\n")?
|
||||
|
||||
}
|
||||
}
|
||||
Cmd::List { all } => {
|
||||
apps.print(all)?;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue