diff --git a/src/common/mime_types.rs b/src/common/mime_types.rs index d041c66..9bd5668 100644 --- a/src/common/mime_types.rs +++ b/src/common/mime_types.rs @@ -2,7 +2,7 @@ use crate::{Error, Result}; use mime::Mime; use std::{ convert::TryFrom, - path::{Path, PathBuf}, + path::{Path}, str::FromStr, }; @@ -30,14 +30,14 @@ impl TryFrom<&str> for MimeType { fn try_from(arg: &str) -> Result { match url::Url::parse(arg) { Ok(url) if url.scheme() == "file" => { - Self::try_from(&*PathBuf::from(url.path())) + Self::try_from(Path::new(url.path())) } Ok(url) => Ok(Self( format!("x-scheme-handler/{}", url.scheme()) .parse::() .unwrap(), )), - Err(_) => Self::try_from(&*PathBuf::from(arg)), + Err(_) => Self::try_from(Path::new(arg)), } } } diff --git a/src/main.rs b/src/main.rs index 258f8b7..490aa5b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,13 +39,23 @@ fn main() -> Result<()> { Cmd::Open { paths } => { let mut handlers: HashMap> = HashMap::new(); + for path in paths.into_iter() { + let path = match url::Url::parse(&path) { + Ok(url) if url.scheme() == "file" => { + url.path().to_owned() + } + _ => path, + }; + let mime = MimeType::try_from(path.as_str())?.0; let handler = apps.get_handler(&mime)?; - handlers.entry(handler).or_insert(Vec::new()).push(path); + + handlers.entry(handler).or_default().push(path); } - for (handler, handled_paths) in handlers.into_iter() { - handler.open(handled_paths)?; + + for (handler, paths) in handlers.into_iter() { + handler.open(paths)?; } } Cmd::List { all } => {