From 3a299fce8e9b472025687262c3d1dd5f54e610e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Em=C4=ABls=20Pi=C5=86=C4=B7is?= Date: Sun, 2 Apr 2017 12:12:23 +0100 Subject: [PATCH] Notification body now gives information about the return code if possible --- main.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/main.rs b/main.rs index 9770513..f122742 100644 --- a/main.rs +++ b/main.rs @@ -6,19 +6,19 @@ use std::{env, io, process}; use std::io::Write; #[cfg(target_os = "macos")] -fn notify(msg: &str) { +fn notify(msg_title: &str, msg_body: &str) { let bundle = mac_notification_sys::get_bundle_identifier("safari").unwrap(); mac_notification_sys::set_application(&bundle).unwrap(); - mac_notification_sys::send_notification(msg, &None, "finished executing", &None).unwrap(); + mac_notification_sys::send_notification(msg_title, &None, msg_body, &None).unwrap(); } #[cfg(not(target_os = "macos"))] -fn notify(msg: &str) { +fn notify(msg_title: &str, msg_body: &str) { use notify_rust::Notification; Notification::new() - .summary(msg) - .body("finished executing") + .summary(msg_title) + .body(msg_body) .show() .unwrap(); } @@ -48,7 +48,7 @@ fn main() { "aa: Unknown command '{}': {}", program_name, e) - .expect("could not write to stderr"); + .expect("could not write to stderr"); process::exit(1); } }; @@ -60,7 +60,17 @@ fn main() { full_cmd.push_str(" "); full_cmd.push_str(&args.join(" ")); - notify(&full_cmd); + let cmd_success = if let Some(code) = exit_status.code() { + if code != 0 { + format!("Command exited with status code {}", code) + } else { + "Command exited successfully".to_string() + } + } else { + "Command exited".to_string() + }; + + notify(&full_cmd, &cmd_success); if let Some(code) = exit_status.code() { process::exit(code); -- 2.51.2