aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/no/notify-run/src
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-12-04 01:45:23 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-12-04 01:45:23 +0100
commitf47ab69e888b5ed7ff167dac55dfa8fc228595de (patch)
tree69e86e9fe9ec5b85aeb4df3f81b2a711a4b28b7c /pkgs/by-name/no/notify-run/src
parentpkgs/notify-run: Actually provide the `makeWrapper` command to the builder (diff)
downloadnixos-config-f47ab69e888b5ed7ff167dac55dfa8fc228595de.zip
pkgs/notify-run: Append the name of the spawned command before printing
Diffstat (limited to '')
-rw-r--r--pkgs/by-name/no/notify-run/src/main.rs23
1 files changed, 20 insertions, 3 deletions
diff --git a/pkgs/by-name/no/notify-run/src/main.rs b/pkgs/by-name/no/notify-run/src/main.rs
index de625627..a6a0165a 100644
--- a/pkgs/by-name/no/notify-run/src/main.rs
+++ b/pkgs/by-name/no/notify-run/src/main.rs
@@ -8,7 +8,7 @@
// 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 std::{env::args, path::PathBuf, process::Command};
use anyhow::{Context, Result};
@@ -40,9 +40,26 @@ fn main() -> Result<()> {
)
})?;
} else {
- print!("{}", String::from_utf8_lossy(&output.stdout));
- eprint!("{}", String::from_utf8_lossy(&output.stderr));
+ let name = PathBuf::from(&args[0])
+ .file_name()
+ .expect("this to be a command, and thus have a file_name")
+ .to_string_lossy()
+ .to_string();
+
+ print!("{}", append_name(&name, &output.stdout));
+ eprint!("{}", append_name(&name, &output.stderr));
}
Ok(())
}
+
+fn append_name(name: &str, base: &[u8]) -> String {
+ let base = String::from_utf8_lossy(base).to_string();
+
+ let mut output = String::new();
+ for line in base.lines() {
+ output.push_str(format!("{name}> {line}\n").as_str());
+ }
+
+ output
+}