diff options
| author | K900 <me@0upti.me> | 2023-02-02 15:26:33 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-02 15:26:33 +0300 |
| commit | e110ed426e1823b32a2409227560af88348f7e24 (patch) | |
| tree | be1c5b8825fab62f8f125c609fc513d2b179212d /scripts/native-utils/src/split_path.rs | |
| parent | 65a6b5aeda9e454d3cd9d75648f59333a0094122 (diff) | |
| parent | deef7819e9863464365bc251c1070708e0925fc0 (diff) | |
Merge pull request #214 from K900/until-morale-improves
feat: use a Rust tool to do the PATH manipulations
Diffstat (limited to 'scripts/native-utils/src/split_path.rs')
| -rw-r--r-- | scripts/native-utils/src/split_path.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/scripts/native-utils/src/split_path.rs b/scripts/native-utils/src/split_path.rs new file mode 100644 index 0000000..dd10745 --- /dev/null +++ b/scripts/native-utils/src/split_path.rs @@ -0,0 +1,38 @@ +use std::env; + +use clap::Parser; + +#[derive(Parser, Debug)] +struct Args { + #[arg(long)] + automount_root: String, + + #[arg(long)] + include_interop: bool, +} + +fn main() -> anyhow::Result<()> { + let args = Args::parse(); + + let path = env::var("PATH")?; + + let mut native = vec![]; + let mut interop = vec![]; + + for part in path.split(':') { + if part.starts_with(&args.automount_root) { + interop.push(part); + } else { + native.push(part); + } + } + + if args.include_interop { + native.extend(&interop); + }; + + println!("export PATH='{}'", native.join(":")); + println!("export WSLPATH='{}'", interop.join(":")); + + Ok(()) +} |
