dos-var: usability improvement and added release profile
This commit is contained in:
parent
2b416b6b2f
commit
30159a43ae
3 changed files with 42 additions and 26 deletions
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -1,36 +1,39 @@
|
|||
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";
|
||||
|
||||
const FLAG_PATH: [&str; 2] = [ "-p", "--path" ];
|
||||
|
||||
pub fn main() {
|
||||
let args: Vec<String> = args().collect();
|
||||
if args.len() != 2 { error::arg_count(); }
|
||||
let target = &args[1];
|
||||
let mut args = Arguments::from_env();
|
||||
|
||||
let cmd = Command::new(CMD)
|
||||
.current_dir("/mnt/c/")
|
||||
.arg( format!("/C echo %{target}%") )
|
||||
.output();
|
||||
if let Ok(output) = cmd {
|
||||
if let Ok(stdout) = String::from_utf8(output.stdout) {
|
||||
// trim output
|
||||
let stdout = stdout.trim_end_matches("\"\r\n");
|
||||
// catch empty variable case
|
||||
if stdout == format!("%{target}%") { error::not_found(&target); }
|
||||
let convert_path = args.contains(FLAG_PATH);
|
||||
|
||||
// convert and write
|
||||
let path = stdout
|
||||
.replace("\\", "/")
|
||||
.replace("C:/", "/mnt/c/");
|
||||
println!("{path}");
|
||||
if let Ok(Some(target)) = args.subcommand() {
|
||||
let cmd = Command::new(CMD)
|
||||
.current_dir("/mnt/c/")
|
||||
.arg( format!("/C echo %{target}%") )
|
||||
.output();
|
||||
if let Ok(output) = cmd {
|
||||
if let Ok(stdout) = String::from_utf8(output.stdout) {
|
||||
// trim output
|
||||
let stdout = stdout.trim_end_matches("\"\r\n");
|
||||
// catch empty variable case
|
||||
if stdout == format!("%{target}%") { error::not_found(&target); }
|
||||
|
||||
// handle path flag and write
|
||||
let path =
|
||||
if convert_path {
|
||||
stdout
|
||||
.replace("\\", "/")
|
||||
.replace("C:/", "/mnt/c/")
|
||||
} else { stdout.to_owned() };
|
||||
println!("{path}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue