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 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}"); } } } else { error::missing_arg(); } }