use std::path::Path; use pico_args::Arguments; const DRIVE: &str = "/mnt/c/"; const QUOTED: [&str;2] = [ "-q", "--quotes" ]; pub fn main() { let mut args = Arguments::from_env(); // handle quote flag let quotes: &str = if args.contains(QUOTED) { if args.contains(QUOTED) { "\"" } // -qq -> "..." (output with double quotes) else { "'" } // -q -> '...' (output with single quotes) } else { "" }; // _ -> ... (output with no quotes) loop { let next = args.subcommand().unwrap(); if let Some(arg) = next { let mut output: String; // canonicalize; windows doesn't recognize symlinks let path = Path::new(&arg).canonicalize(); if let Ok(target) = path { output = target.to_string_lossy().to_string(); } else { output = arg; } // simple C-drive substitution if output.starts_with(DRIVE) { output = output.replace(DRIVE, "C:\\"); } // switch out separators output = output.replace("/", "\\"); // emit to stdout println!("{quotes}{output}{quotes}"); } else { break; } } }