From f7e215b54858fb8d3464a432b76b46f4f1599697 Mon Sep 17 00:00:00 2001 From: Valerie Wolfe Date: Tue, 11 Jun 2024 10:05:41 -0400 Subject: [PATCH] path-convert: added flag to emit network paths --- path-convert/Cargo.toml | 2 +- path-convert/src/main.rs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/path-convert/Cargo.toml b/path-convert/Cargo.toml index f8813a4..7307ecc 100644 --- a/path-convert/Cargo.toml +++ b/path-convert/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "path-convert" -version = "0.0.4" +version = "0.0.5" edition = "2021" [dependencies] diff --git a/path-convert/src/main.rs b/path-convert/src/main.rs index 6f8f841..a368f27 100644 --- a/path-convert/src/main.rs +++ b/path-convert/src/main.rs @@ -2,9 +2,15 @@ use std::path::{ Path, PathBuf }; use pico_args::Arguments; +// - HELPER - const DRIVE: &str = "/mnt/c/"; +// - ENV - +const DISTRO: &str = "WSL_DISTRO_NAME"; + +// - FLAGS - const HELP: [&str;2] = [ "-h", "--help" ]; +const NET_PATH: [&str;2] = [ "-n", "--network-path" ]; const NO_SPACES: [&str;2] = [ "-s", "--no-space" ]; const QUOTED: [&str;2] = [ "-q", "--quotes" ]; @@ -24,8 +30,9 @@ pub fn main() { else { "'" } // -q -> '...' (output with single quotes) } else { "" }; // _ -> ... (output with no quotes) - // collect no-space flag + // consume simple flags let no_spaces = args.contains(NO_SPACES); + let network_path = args.contains(NET_PATH); loop { let next = args.subcommand().unwrap(); @@ -78,6 +85,11 @@ pub fn main() { // simple C-drive substitution if output.starts_with(DRIVE) { output = output.replace(DRIVE, "C:\\"); + } else if network_path { + let name = std::env::var(DISTRO); + if let Ok(name) = name { + output = format!("//wsl.localhost/{name}{output}"); + } } // switch out separators