mirror of
https://github.com/chmln/handlr.git
synced 2024-11-14 05:29:28 +01:00
Handle directories
This commit is contained in:
parent
51cee47684
commit
8d26b7f5dd
3 changed files with 12 additions and 7 deletions
|
@ -1,2 +1,2 @@
|
|||
max_width = 80
|
||||
merge-imports = true
|
||||
merge_imports = true
|
||||
|
|
|
@ -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,
|
||||
|
|
15
src/main.rs
15
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 => {
|
||||
|
|
Loading…
Reference in a new issue