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
assume you have PowerShell somewhere in your `PATH` as "`pwsh`".
## `dos-var`
Gets Windows environment variables from DOS.
## `env-share`
A hacked-together utility for sending WSL variables back to Windows

View file

@ -1,6 +1,15 @@
[package]
name = "dos-var"
version = "0.0.1"
version = "0.0.2"
edition = "2021"
[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::{
env::args,
process::{
Command,
Stdio
}
};
use std::process::Command;
use pico_args::Arguments;
mod error;
const CMD: &str = "/mnt/c/Windows/System32/cmd.exe";
pub fn main() {
let args: Vec<String> = args().collect();
if args.len() != 2 { error::arg_count(); }
let target = &args[1];
const FLAG_PATH: [&str; 2] = [ "-p", "--path" ];
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)
.current_dir("/mnt/c/")
.arg( format!("/C echo %{target}%") )
@ -26,12 +25,16 @@ pub fn main() {
// catch empty variable case
if stdout == format!("%{target}%") { error::not_found(&target); }
// convert and write
let path = stdout
// handle path flag and write
let path =
if convert_path {
stdout
.replace("\\", "/")
.replace("C:/", "/mnt/c/");
.replace("C:/", "/mnt/c/")
} else { stdout.to_owned() };
println!("{path}");
}
}
}
}