Merge branch 'hug'

This commit is contained in:
Valerie Wolfe 2024-07-16 09:05:11 -04:00
commit 2d88ac6f45
7 changed files with 87 additions and 0 deletions

View file

@ -13,6 +13,10 @@ Gets Windows environment variables from DOS.
A hacked-together utility for sending WSL variables back to Windows A hacked-together utility for sending WSL variables back to Windows
shells. The utility runs in WSL, and companion scripts run in 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` ## `mkwin`
A Linux utility to quickly make a bash script to run a Windows executable with A Linux utility to quickly make a bash script to run a Windows executable with

2
hug/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/target
Cargo.lock

13
hug/Cargo.toml Normal file
View file

@ -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"

10
hug/justfile Normal file
View file

@ -0,0 +1,10 @@
alias b := build
alias i := install
build:
cargo build --release
install DIR: build
cp ./target/release/hug "{{DIR}}/hug"

32
hug/src/main.rs Normal file
View file

@ -0,0 +1,32 @@
use std::{
env,
process::{ Command, Stdio }
};
fn main() {
let mut args: Vec<String> = 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),
}
}
}
}

View file

@ -11,6 +11,7 @@ install TARGET='all' DIR="~/.bin/":
just install scripts {{DIR}} just install scripts {{DIR}}
just install dos-var {{DIR}} just install dos-var {{DIR}}
just install env-share {{DIR}} just install env-share {{DIR}}
just install hug {{DIR}}
just install mkwin {{DIR}} just install mkwin {{DIR}}
just install path-convert {{DIR}} just install path-convert {{DIR}}
just install qdls {{DIR}} just install qdls {{DIR}}

25
man/hug.1 Normal file
View file

@ -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