mirror of
https://github.com/chmln/handlr.git
synced 2024-11-14 13:39:29 +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
|
max_width = 80
|
||||||
merge-imports = true
|
merge_imports = true
|
||||||
|
|
|
@ -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,
|
||||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -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 => {
|
||||||
|
|
Loading…
Reference in a new issue