diff --git a/completions/handlr.fish b/completions/handlr.fish index cf2d346..76e7e92 100644 --- a/completions/handlr.fish +++ b/completions/handlr.fish @@ -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)' diff --git a/src/apps/user.rs b/src/apps/user.rs index aa591e2..58707c1 100644 --- a/src/apps/user.rs +++ b/src/apps/user.rs @@ -51,11 +51,20 @@ impl MimeApps { .into_iter() .map(|h| (h, h.get_entry().unwrap().name)) .collect::>(); - 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 diff --git a/src/config.rs b/src/config.rs index 35b63b4..626fb39 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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) } diff --git a/src/error.rs b/src/error.rs index 8d37679..9eea3c6 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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 = std::result::Result;