From 8f7e820d10e149ec642c3b4fd551b90d7468e3be Mon Sep 17 00:00:00 2001 From: beet <63141491+beetcb@users.noreply.github.com> Date: Sun, 5 Dec 2021 01:04:31 +0800 Subject: [PATCH] fix(PATH): add ability to concat PATH on any platform (#24) --- src/lib.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index daca963..3f9670f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,12 +13,16 @@ use std::process::{exit, Command}; // Get PATH env and join it with bin_dir fn get_path_env(bin_dirs: Vec) -> String { - let mut path = env::var("PATH").unwrap_or_default(); - for dir in bin_dirs { - path.push_str(":"); - path.push_str(dir.to_str().unwrap()); - } - path + let path = PathBuf::from(env::var("PATH").unwrap_or_default()); + env::join_paths( + bin_dirs + .iter() + .chain(env::split_paths(&path).collect::>().iter()), + ) + .ok() + .unwrap() + .into_string() + .unwrap() } // A function to find the closest file