summaryrefslogtreecommitdiff
path: root/scripts/native-utils/src/split_path.rs
diff options
context:
space:
mode:
authorK900 <me@0upti.me>2023-02-02 15:26:33 +0300
committerGitHub <noreply@github.com>2023-02-02 15:26:33 +0300
commite110ed426e1823b32a2409227560af88348f7e24 (patch)
treebe1c5b8825fab62f8f125c609fc513d2b179212d /scripts/native-utils/src/split_path.rs
parent65a6b5aeda9e454d3cd9d75648f59333a0094122 (diff)
parentdeef7819e9863464365bc251c1070708e0925fc0 (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.rs38
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(())
+}