diff --git a/.rustfmt.toml b/.rustfmt.toml index be300b2..1e3fc2f 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -1,2 +1,2 @@ max_width = 80 -merge-imports = true +merge_imports = true diff --git a/src/error.rs b/src/error.rs index 43bdd2e..932a11c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -10,7 +10,7 @@ pub enum Error { BadCmd, #[error("could not locate config dir")] NoConfigDir, - #[error("could not figure out the mime from extension. please provide the mime type directly")] + #[error("could not figure out the mime type")] Ambiguous, #[error("either mime (via -m) or extension (via -e) must be provided")] MissingMimeOrExt, diff --git a/src/main.rs b/src/main.rs index 36aaa53..6ce582d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,14 +69,19 @@ fn main() -> Result<()> { Cmd::Open { path } => match url::Url::parse(&path) { Ok(url) => { let mime = Mime(format!("x-scheme-handler/{}", url.scheme())); - apps.get_handler(&mime)?.open(path)?; } Err(_) => { - let guess = mime_guess::from_path(&path) - .first_or_text_plain() - .to_string(); - apps.get_handler(&Mime(guess))?.open(path)?; + let mime = match mime_guess::from_path(&path).first_raw() { + Some(mime) => mime, + None if std::fs::metadata(&path)?.is_dir() => { + "inode/directory" + } + _ => { + return Err(Error::Ambiguous); + } + }; + apps.get_handler(&Mime(mime.to_owned()))?.open(path)?; } }, Cmd::List => {