Skip to content

Commit

Permalink
Merge pull request #11 from n3tw0rth/dev
Browse files Browse the repository at this point in the history
updates
  • Loading branch information
n3tw0rth authored Feb 12, 2025
2 parents 58fc304 + fa04fb3 commit 3ef1f78
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tokio::io::{AsyncReadExt, AsyncWriteExt};
use super::Config;

pub async fn app_state() -> anyhow::Result<Config> {
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);
Expand Down
25 changes: 11 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ struct Args {

#[arg(short, long)]
triggers: Option<String>,

#[arg(long, action)]
verbose: bool,
}

#[derive(Deserialize, Debug)]
Expand Down Expand Up @@ -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);

Expand All @@ -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::<Vec<_>>()
.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();
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}

0 comments on commit 3ef1f78

Please sign in to comment.