Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::io::Write;

use config::CONFIG;
use error::{Error, Result};
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -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)?;
}
Expand Down