path-convert: added flag to emit network paths
This commit is contained in:
parent
f62b201c14
commit
f7e215b548
2 changed files with 14 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "path-convert"
|
||||
version = "0.0.4"
|
||||
version = "0.0.5"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue