diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-11-29 21:17:01 +0100 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-11-29 21:17:01 +0100 |
| commit | c9ccf8491f732499fb9e1834e61b4edc77d18423 (patch) | |
| tree | 511366c2be4843bdef613e336c6ecef2c2c9c5ec /pkgs/by-name/no/notify-run/src | |
| parent | modules/qutebrowser: Change default search engine (diff) | |
| download | nixos-config-c9ccf8491f732499fb9e1834e61b4edc77d18423.zip | |
pkgs/notify-run: Init
Diffstat (limited to 'pkgs/by-name/no/notify-run/src')
| -rw-r--r-- | pkgs/by-name/no/notify-run/src/main.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/pkgs/by-name/no/notify-run/src/main.rs b/pkgs/by-name/no/notify-run/src/main.rs new file mode 100644 index 00000000..18b7af58 --- /dev/null +++ b/pkgs/by-name/no/notify-run/src/main.rs @@ -0,0 +1,46 @@ +// nixos-config - My current NixOS configuration +// +// Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de> +// SPDX-License-Identifier: GPL-3.0-or-later +// +// This file is part of my nixos-config. +// +// You should have received a copy of the License along with this program. +// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. + +use std::{env::args, process::Command}; + +use anyhow::{Context, Result}; + +fn main() -> Result<()> { + let args = args().skip(1).collect::<Vec<_>>(); + + let mut cmd = Command::new(&args[0]); + cmd.args(&args[1..]); + + eprintln!("Spawning {:?}", cmd); + + let output = cmd + .output() + .with_context(|| format!("Failed to spawn and await output of {:?}", cmd))?; + + if !output.status.success() { + let mut notify_send = Command::new("notify-send"); + notify_send.args([ + format!("Command {:?} failed", cmd).as_str(), + &String::from_utf8_lossy(output.stderr.as_slice()), + ]); + + notify_send.status().with_context(|| { + format!( + "Failed to run `notify-send` to tell about failed command ({:?}).", + cmd + ) + })?; + } else { + print!("{}", String::from_utf8_lossy(&output.stdout)); + eprint!("{}", String::from_utf8_lossy(&output.stderr)); + } + + Ok(()) +} |
