Handle directories

This commit is contained in:
Gregory 2020-05-17 00:45:25 -04:00
parent 51cee47684
commit 8d26b7f5dd
No known key found for this signature in database
GPG key ID: 2E44FAEEDC94B1E2
3 changed files with 12 additions and 7 deletions

View file

@ -1,2 +1,2 @@
max_width = 80
merge-imports = true
merge_imports = true

View file

@ -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,

View file

@ -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 => {