diff --git a/README.md b/README.md index 21014bd..ef5d892 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Install directly from source it is better to use a alias for the binary, ```bash #.bashrc -alias notif='completion-notifier' +alias notify='completion-notifier' ``` ## Usage diff --git a/src/helpers.rs b/src/helpers.rs index ebd580e..b75ae94 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -4,7 +4,7 @@ use tokio::io::{AsyncReadExt, AsyncWriteExt}; use super::Config; pub async fn app_state() -> anyhow::Result { - let config_path = dirs::config_dir().unwrap().join("fetched"); + let config_path = dirs::config_dir().unwrap().join("completion-notifier"); let filename = "config.toml"; let path = config_path.join(filename); diff --git a/src/main.rs b/src/main.rs index e0e83c7..7b092f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,9 +28,6 @@ struct Args { #[arg(short, long)] triggers: Option, - - #[arg(long, action)] - verbose: bool, } #[derive(Deserialize, Debug)] @@ -59,12 +56,11 @@ struct EmailConfig { #[tokio::main] async fn main() -> anyhow::Result<()> { + // Parse the command line arguments let mut args = Args::parse(); let config = helpers::app_state().await?; - // helpers::handle_ctrlc().await; - let program = args.run.get(0).cloned().unwrap(); let program_args = args.run.split_off(1); @@ -87,23 +83,24 @@ async fn main() -> anyhow::Result<()> { if args.triggers.is_some() { // Check if the line contains a trigger string - let contains_a_trigger = args + let contained_triggers: Vec<_> = args .triggers .as_ref() .unwrap() .split(",") - .collect::>() - .iter() - .any(|t| line.contains(t)); - if contains_a_trigger { - let _ = notification::Notification::new( + .filter(|trigger| line.contains(trigger)) + .collect(); + + if contained_triggers.len() > 0 { + notification::Notification::new( &config, &args.profiles.as_ref().unwrap(), "Trigger Detected".to_string(), - "".to_string(), + contained_triggers.join(","), ) - .send() - .await; + .send_trigger() + .await + .unwrap(); } } } diff --git a/src/notification.rs b/src/notification.rs index d57f54a..d397b98 100644 --- a/src/notification.rs +++ b/src/notification.rs @@ -115,4 +115,11 @@ impl<'b> Notification<'b> { Ok(()) } + + pub async fn send_trigger(&mut self) -> anyhow::Result<()> { + // expect a list of triggers found and will update the notification massage based on that + self.msg = format!("Triggers invoked {}", self.msg); + self.send().await?; + Ok(()) + } }