summaryrefslogtreecommitdiff
path: root/scripts/native-utils/src/split_path.rs
blob: dd107453478d2981900e0a2e85194a202458c318 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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(())
}