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]
|
[package]
|
||||||
name = "path-convert"
|
name = "path-convert"
|
||||||
version = "0.0.4"
|
version = "0.0.5"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
@ -2,9 +2,15 @@ use std::path::{ Path, PathBuf };
|
||||||
|
|
||||||
use pico_args::Arguments;
|
use pico_args::Arguments;
|
||||||
|
|
||||||
|
// - HELPER -
|
||||||
const DRIVE: &str = "/mnt/c/";
|
const DRIVE: &str = "/mnt/c/";
|
||||||
|
|
||||||
|
// - ENV -
|
||||||
|
const DISTRO: &str = "WSL_DISTRO_NAME";
|
||||||
|
|
||||||
|
// - FLAGS -
|
||||||
const HELP: [&str;2] = [ "-h", "--help" ];
|
const HELP: [&str;2] = [ "-h", "--help" ];
|
||||||
|
const NET_PATH: [&str;2] = [ "-n", "--network-path" ];
|
||||||
const NO_SPACES: [&str;2] = [ "-s", "--no-space" ];
|
const NO_SPACES: [&str;2] = [ "-s", "--no-space" ];
|
||||||
const QUOTED: [&str;2] = [ "-q", "--quotes" ];
|
const QUOTED: [&str;2] = [ "-q", "--quotes" ];
|
||||||
|
|
||||||
|
@ -24,8 +30,9 @@ pub fn main() {
|
||||||
else { "'" } // -q -> '...' (output with single quotes)
|
else { "'" } // -q -> '...' (output with single quotes)
|
||||||
} else { "" }; // _ -> ... (output with no quotes)
|
} else { "" }; // _ -> ... (output with no quotes)
|
||||||
|
|
||||||
// collect no-space flag
|
// consume simple flags
|
||||||
let no_spaces = args.contains(NO_SPACES);
|
let no_spaces = args.contains(NO_SPACES);
|
||||||
|
let network_path = args.contains(NET_PATH);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let next = args.subcommand().unwrap();
|
let next = args.subcommand().unwrap();
|
||||||
|
@ -78,6 +85,11 @@ pub fn main() {
|
||||||
// simple C-drive substitution
|
// simple C-drive substitution
|
||||||
if output.starts_with(DRIVE) {
|
if output.starts_with(DRIVE) {
|
||||||
output = output.replace(DRIVE, "C:\\");
|
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
|
// switch out separators
|
||||||
|
|
Loading…
Reference in a new issue