dos-var: usability improvement and added release profile

This commit is contained in:
Valerie Wolfe 2024-07-12 14:16:07 -04:00
parent 2b416b6b2f
commit 30159a43ae
3 changed files with 42 additions and 26 deletions

View file

@ -4,6 +4,10 @@
These are tools I use to use Windows primarily through WSL. A lot of them These are tools I use to use Windows primarily through WSL. A lot of them
assume you have PowerShell somewhere in your `PATH` as "`pwsh`". assume you have PowerShell somewhere in your `PATH` as "`pwsh`".
## `dos-var`
Gets Windows environment variables from DOS.
## `env-share` ## `env-share`
A hacked-together utility for sending WSL variables back to Windows A hacked-together utility for sending WSL variables back to Windows

View file

@ -1,6 +1,15 @@
[package] [package]
name = "dos-var" name = "dos-var"
version = "0.0.1" version = "0.0.2"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
pico-args = "0.5.0"
[profile.release]
opt-level = 's'
codegen-units = 1
debug = false
lto = true
panic = "abort"
strip = "symbols"

View file

@ -1,20 +1,19 @@
use std::{ use std::process::Command;
env::args,
process::{ use pico_args::Arguments;
Command,
Stdio
}
};
mod error; mod error;
const CMD: &str = "/mnt/c/Windows/System32/cmd.exe"; const CMD: &str = "/mnt/c/Windows/System32/cmd.exe";
pub fn main() { const FLAG_PATH: [&str; 2] = [ "-p", "--path" ];
let args: Vec<String> = args().collect();
if args.len() != 2 { error::arg_count(); }
let target = &args[1];
pub fn main() {
let mut args = Arguments::from_env();
let convert_path = args.contains(FLAG_PATH);
if let Ok(Some(target)) = args.subcommand() {
let cmd = Command::new(CMD) let cmd = Command::new(CMD)
.current_dir("/mnt/c/") .current_dir("/mnt/c/")
.arg( format!("/C echo %{target}%") ) .arg( format!("/C echo %{target}%") )
@ -26,12 +25,16 @@ pub fn main() {
// catch empty variable case // catch empty variable case
if stdout == format!("%{target}%") { error::not_found(&target); } if stdout == format!("%{target}%") { error::not_found(&target); }
// convert and write // handle path flag and write
let path = stdout let path =
if convert_path {
stdout
.replace("\\", "/") .replace("\\", "/")
.replace("C:/", "/mnt/c/"); .replace("C:/", "/mnt/c/")
} else { stdout.to_owned() };
println!("{path}"); println!("{path}");
} }
} }
}
} }