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 max_width = 80
merge-imports = true merge_imports = true

View file

@ -10,7 +10,7 @@ pub enum Error {
BadCmd, BadCmd,
#[error("could not locate config dir")] #[error("could not locate config dir")]
NoConfigDir, 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, Ambiguous,
#[error("either mime (via -m) or extension (via -e) must be provided")] #[error("either mime (via -m) or extension (via -e) must be provided")]
MissingMimeOrExt, MissingMimeOrExt,

View file

@ -69,14 +69,19 @@ fn main() -> Result<()> {
Cmd::Open { path } => match url::Url::parse(&path) { Cmd::Open { path } => match url::Url::parse(&path) {
Ok(url) => { Ok(url) => {
let mime = Mime(format!("x-scheme-handler/{}", url.scheme())); let mime = Mime(format!("x-scheme-handler/{}", url.scheme()));
apps.get_handler(&mime)?.open(path)?; apps.get_handler(&mime)?.open(path)?;
} }
Err(_) => { Err(_) => {
let guess = mime_guess::from_path(&path) let mime = match mime_guess::from_path(&path).first_raw() {
.first_or_text_plain() Some(mime) => mime,
.to_string(); None if std::fs::metadata(&path)?.is_dir() => {
apps.get_handler(&Mime(guess))?.open(path)?; "inode/directory"
}
_ => {
return Err(Error::Ambiguous);
}
};
apps.get_handler(&Mime(mime.to_owned()))?.open(path)?;
} }
}, },
Cmd::List => { Cmd::List => {