This commit is contained in:
Gregory 2020-06-12 14:45:25 -04:00
parent 44f533fe8f
commit dc12926bd4
No known key found for this signature in database
GPG key ID: 2E44FAEEDC94B1E2
4 changed files with 32 additions and 14 deletions

View file

@ -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)'

View file

@ -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

View file

@ -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)
}

View file

@ -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>;