2024-07-12 14:16:07 -04:00
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
use pico_args::Arguments;
|
2024-07-12 14:05:01 -04:00
|
|
|
|
|
|
|
mod error;
|
|
|
|
|
|
|
|
const CMD: &str = "/mnt/c/Windows/System32/cmd.exe";
|
|
|
|
|
2024-07-12 14:16:07 -04:00
|
|
|
const FLAG_PATH: [&str; 2] = [ "-p", "--path" ];
|
|
|
|
|
2024-07-12 14:05:01 -04:00
|
|
|
pub fn main() {
|
2024-07-12 14:16:07 -04:00
|
|
|
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}%") )
|
|
|
|
.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}");
|
|
|
|
}
|
2024-07-12 14:05:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|