mirror of
https://github.com/chmln/handlr.git
synced 2024-11-14 13:39:29 +01:00
Cleanup
This commit is contained in:
parent
44f533fe8f
commit
dc12926bd4
4 changed files with 32 additions and 14 deletions
2
completions/handlr.fish
vendored
2
completions/handlr.fish
vendored
|
@ -18,7 +18,7 @@ function __handlr_autocomplete
|
|||
end
|
||||
|
||||
subcommands
|
||||
_set
|
||||
_set_add
|
||||
complete -f -c handlr -n '__fish_seen_subcommand_from get' -a '(handlr autocomplete -m)'
|
||||
complete -f -c handlr -n '__fish_seen_subcommand_from get' -l 'json'
|
||||
complete -f -c handlr -n '__fish_seen_subcommand_from unset' -a '(handlr autocomplete -m)'
|
||||
|
|
|
@ -51,11 +51,20 @@ impl MimeApps {
|
|||
.into_iter()
|
||||
.map(|h| (h, h.get_entry().unwrap().name))
|
||||
.collect::<Vec<_>>();
|
||||
let selected =
|
||||
config.select(handlers.iter().map(|h| h.1.clone()))?;
|
||||
let selected =
|
||||
handlers.into_iter().find(|h| h.1 == selected).unwrap().0;
|
||||
Ok(selected.clone())
|
||||
|
||||
let handler = {
|
||||
let name =
|
||||
config.select(handlers.iter().map(|h| h.1.clone()))?;
|
||||
|
||||
handlers
|
||||
.into_iter()
|
||||
.find(|h| h.1 == name)
|
||||
.unwrap()
|
||||
.0
|
||||
.clone()
|
||||
};
|
||||
|
||||
Ok(handler)
|
||||
}
|
||||
Some(handlers) => Ok(handlers.get(0).unwrap().clone()),
|
||||
None => self
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::Result;
|
||||
use crate::{Error, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
|
@ -41,14 +41,21 @@ impl Config {
|
|||
.spawn()?
|
||||
};
|
||||
|
||||
process
|
||||
.stdin
|
||||
.unwrap()
|
||||
.write_all(opts.join("\n").as_bytes())?;
|
||||
let output = {
|
||||
process
|
||||
.stdin
|
||||
.ok_or(Error::Selector(self.selector.clone()))?
|
||||
.write_all(opts.join("\n").as_bytes())?;
|
||||
|
||||
let mut output = String::with_capacity(24);
|
||||
process.stdout.unwrap().read_to_string(&mut output)?;
|
||||
let output = output.trim_end().to_owned();
|
||||
let mut output = String::with_capacity(24);
|
||||
|
||||
process
|
||||
.stdout
|
||||
.ok_or(Error::Selector(self.selector.clone()))?
|
||||
.read_to_string(&mut output)?;
|
||||
|
||||
output.trim_end().to_owned()
|
||||
};
|
||||
|
||||
Ok(output)
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ pub enum Error {
|
|||
BadEntry(std::path::PathBuf),
|
||||
#[error(transparent)]
|
||||
MimeDetect(#[from] mime_detective::DetectiveError),
|
||||
#[error("error spawning selector process '{0}'")]
|
||||
Selector(String),
|
||||
}
|
||||
|
||||
pub type Result<T, E = Error> = std::result::Result<T, E>;
|
||||
|
|
Loading…
Reference in a new issue