From 43d5cbd4aa4e6353c658761e091088f77fcc81c3 Mon Sep 17 00:00:00 2001 From: Valerie Wolfe Date: Mon, 15 Jul 2024 13:21:43 -0400 Subject: [PATCH 1/4] hug: initial implementation --- README.md | 4 ++++ hug/.gitignore | 2 ++ hug/Cargo.toml | 13 +++++++++++++ hug/src/main.rs | 31 +++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 hug/.gitignore create mode 100644 hug/Cargo.toml create mode 100644 hug/src/main.rs diff --git a/README.md b/README.md index 4b351f4..b8df0d8 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,10 @@ Gets Windows environment variables from DOS. A hacked-together utility for sending WSL variables back to Windows shells. The utility runs in WSL, and companion scripts run in Windows. +## `hug` + +A wrapper for turning binary-output text into normal text. + ## `mkwin` A Linux utility to quickly make a bash script to run a Windows executable with diff --git a/hug/.gitignore b/hug/.gitignore new file mode 100644 index 0000000..96ef6c0 --- /dev/null +++ b/hug/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/hug/Cargo.toml b/hug/Cargo.toml new file mode 100644 index 0000000..088140e --- /dev/null +++ b/hug/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "hug" +version = "0.0.1" +edition = "2021" + +[profile.release] +opt-level = 's' +codegen-units = 1 +debug = false +lto = true +panic = "abort" +strip = "symbols" + diff --git a/hug/src/main.rs b/hug/src/main.rs new file mode 100644 index 0000000..4ea44a6 --- /dev/null +++ b/hug/src/main.rs @@ -0,0 +1,31 @@ +use std::{ + env, net::ToSocketAddrs, process::{ Command, Stdio } +}; + +fn main() { + let mut args: Vec = env::args().collect(); + args.remove(0); + + let target = args.remove(0); + let command = Command::new(target) + .args(args) + .stderr(Stdio::inherit()) + .output(); + if let Ok(output) = command { + let mut line = String::new(); + for byte in output.stdout { + match char::from_u32(byte.into()) { + Some('\n') => { + println!("{line}"); + line = String::new(); + }, + + Some('\0') | + None => continue, + + Some(c) => line.push(c), + } + } + } + +} From 5775412f18b550f8120cafa5f5deb50ca7889cfe Mon Sep 17 00:00:00 2001 From: Valerie Wolfe Date: Mon, 15 Jul 2024 13:22:57 -0400 Subject: [PATCH 2/4] hug: removed mystery import? --- hug/src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hug/src/main.rs b/hug/src/main.rs index 4ea44a6..4498d17 100644 --- a/hug/src/main.rs +++ b/hug/src/main.rs @@ -1,5 +1,6 @@ use std::{ - env, net::ToSocketAddrs, process::{ Command, Stdio } + env, + process::{ Command, Stdio } }; fn main() { From baacf638e72e8aae6d25fe194b3e41ab9bb6e3b1 Mon Sep 17 00:00:00 2001 From: Valerie Wolfe Date: Mon, 15 Jul 2024 13:35:35 -0400 Subject: [PATCH 3/4] hug: added just scripts --- hug/justfile | 10 ++++++++++ justfile | 1 + 2 files changed, 11 insertions(+) create mode 100644 hug/justfile diff --git a/hug/justfile b/hug/justfile new file mode 100644 index 0000000..e8e9a03 --- /dev/null +++ b/hug/justfile @@ -0,0 +1,10 @@ + +alias b := build +alias i := install + +build: + cargo build --release + +install DIR: build + cp ./target/release/hug "{{DIR}}/hug" + diff --git a/justfile b/justfile index 6297e94..326a64b 100644 --- a/justfile +++ b/justfile @@ -11,6 +11,7 @@ install TARGET='all' DIR="~/.bin/": just install scripts {{DIR}} just install dos-var {{DIR}} just install env-share {{DIR}} + just install hug {{DIR}} just install mkwin {{DIR}} just install path-convert {{DIR}} just install qdls {{DIR}} From 5589490fe28b03f138082b631872933fd5572790 Mon Sep 17 00:00:00 2001 From: Valerie Wolfe Date: Mon, 15 Jul 2024 14:00:02 -0400 Subject: [PATCH 4/4] man: created 'hug' manual --- README.md | 2 +- man/hug.1 | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 man/hug.1 diff --git a/README.md b/README.md index b8df0d8..490d8ee 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ shells. The utility runs in WSL, and companion scripts run in Windows. ## `hug` -A wrapper for turning binary-output text into normal text. +A barebones command wrapper for turning binary-output text into normal text. ## `mkwin` diff --git a/man/hug.1 b/man/hug.1 new file mode 100644 index 0000000..c840216 --- /dev/null +++ b/man/hug.1 @@ -0,0 +1,25 @@ +.Dd $Mdocdate$ +.Dt HUG 1 +.Os WSL +.Sh NAME +.Nm hug +.Nd wraps processes and converts binary output to text +.Sh SYNOPSIS +.Nm +.Ar target +.Op Ar args... +.Sh DESCRIPTION +The +.Nm +utility runs a process and emits bytes from standard output to text. +.Sh EXAMPLES +WSL's help text is output as binary content, preventing piping to utilities like +.Xr less 1 +or +.Xr bat 1 : +.Pp +.Dl $ hug wsl --help | less +.Pp +.Sh Authors +.An -nosplit +.An Valerie Wolfe Aq Mt sleeplessval@gmail.com