aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <yvchraiqi@protonmail.com>2022-08-18 23:20:11 +0200
committermetamuffin <yvchraiqi@protonmail.com>2022-08-18 23:20:11 +0200
commit47416353ddf7c1c8c2d52908e3884a8e39f9cf85 (patch)
tree8cdfee777482ae7eaa6e8c09fffdb25d8d476655
downloaddesterr-47416353ddf7c1c8c2d52908e3884a8e39f9cf85.tar
desterr-47416353ddf7c1c8c2d52908e3884a8e39f9cf85.tar.bz2
desterr-47416353ddf7c1c8c2d52908e3884a8e39f9cf85.tar.zst
-rw-r--r--.gitignore1
-rw-r--r--COPYING15
-rw-r--r--Cargo.lock7
-rw-r--r--Cargo.toml6
-rw-r--r--readme.md16
-rw-r--r--src/main.rs37
6 files changed, 82 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ea8c4bf
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/target
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..4cb8dc7
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,15 @@
+desterr - tool to destinguish stderr and stdout
+Copyright (C) 2022 metamuffin
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as
+published by the Free Software Foundation, version 3 of the
+License only.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program. If not, see <https://www.gnu.org/licenses/>.
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644
index 0000000..be1a8ab
--- /dev/null
+++ b/Cargo.lock
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "desterr"
+version = "0.1.0"
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..972d88b
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "desterr"
+version = "0.1.0"
+edition = "2021"
+authors = ["metamuffin <metamuffin@disroot.org>"]
+license = "AGPL-3.0-only"
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..71753a2
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,16 @@
+# desterr
+
+Destinguish stderr from stdout, when its not obvious.
+
+## Usage
+
+`desterr <command>`
+
+## Examples
+
+```
+echo 'cat: evil: No such file or directory' > evil
+
+desterr cat normal # error will be red here
+desterr cat evil # error is white
+```
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..f16a236
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+
+use std::{
+ io::{Read, Write},
+ process::{exit, Command, Stdio},
+};
+
+fn main() {
+ let args = std::env::args().skip(1);
+
+ let args = args.collect::<Vec<_>>();
+ if args.len() == 0 {
+ eprintln!("desterr: no command");
+ exit(1);
+ }
+
+ let mut proc = Command::new(&args[0])
+ .args(&args[1..])
+ .stderr(Stdio::piped())
+ .stdout(Stdio::inherit())
+ .stdin(Stdio::inherit())
+ .spawn()
+ .unwrap();
+
+ let mut cstderr = proc.stderr.take().unwrap();
+ let mut buf = [0u8; 1024];
+ let mut pstderr = std::io::stderr();
+
+ while let Ok(r) = cstderr.read(&mut buf) {
+ if r == 0 {
+ break;
+ }
+ pstderr.write_fmt(format_args!("\x1b[31m")).unwrap();
+ pstderr.write(&buf[..r]).unwrap();
+ pstderr.write_fmt(format_args!("\x1b[0m")).unwrap();
+ }
+}