diff --git a/README.md b/README.md index 4b351f4..490d8ee 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 barebones command 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/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/hug/src/main.rs b/hug/src/main.rs new file mode 100644 index 0000000..4498d17 --- /dev/null +++ b/hug/src/main.rs @@ -0,0 +1,32 @@ +use std::{ + env, + 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), + } + } + } + +} 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}} 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