Skip to content

Commit

Permalink
fix: use join_paths to create new_path
Browse files Browse the repository at this point in the history
  • Loading branch information
finalchild committed Oct 6, 2024
1 parent b06878d commit f6b4c8d
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/cli/hook_env.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::env::{join_paths, split_paths};
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::path::{Path, PathBuf, MAIN_SEPARATOR};

use console::truncate_str;
use eyre::Result;
Expand Down Expand Up @@ -99,19 +99,22 @@ impl HookEnv {
) -> Result<Vec<EnvDiffOperation>> {
let full = join_paths(&*env::PATH)?.to_string_lossy().to_string();
let (pre, post) = match &*env::__MISE_ORIG_PATH {
Some(orig_path) => match full.split_once(&format!(":{orig_path}")) {
Some(orig_path) => match full.split_once(&format!("{MAIN_SEPARATOR}{orig_path}")) {
Some((pre, post)) if !settings.activate_aggressive => {
(pre.to_string(), (orig_path.to_string() + post))
(split_paths(pre).collect_vec(), split_paths(&format!("{orig_path}{post}")).collect_vec())
}
_ => (String::new(), full),
_ => (vec![], split_paths(&full).collect_vec()),
},
None => (String::new(), full),
None => (vec![], split_paths(&full).collect_vec()),
};
let install_path = join_paths(installs)?.to_string_lossy().to_string();
let new_path = vec![pre, install_path, post]
.into_iter()
.filter(|p| !p.is_empty())
.join(":");

let new_path = join_paths(
pre.iter()
.chain(installs.iter())
.chain(post.iter()),
)?
.to_string_lossy()
.into_owned();
let mut ops = vec![EnvDiffOperation::Add(PATH_KEY.to_string(), new_path)];

if let Some(input) = env::DIRENV_DIFF.deref() {
Expand Down

0 comments on commit f6b4c8d

Please sign in to comment.