Skip to content

Commit a06bcce

Browse files
committed
fix: windows paths
1 parent fc2cd48 commit a06bcce

File tree

17 files changed

+83
-45
lines changed

17 files changed

+83
-45
lines changed

src/cli/activate.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::path::{Path, PathBuf};
22

33
use eyre::Result;
44

5+
use crate::env::PATH_KEY;
56
use crate::file::touch_dir;
67
use crate::shell::{get_shell, Shell, ShellType};
78
use crate::{dirs, env};
@@ -97,7 +98,7 @@ impl Activate {
9798

9899
fn prepend_path(&self, shell: &dyn Shell, p: &Path) -> String {
99100
if is_dir_not_in_nix(p) && !is_dir_in_path(p) && !p.is_relative() {
100-
shell.prepend_env("PATH", p.to_string_lossy().as_ref())
101+
shell.prepend_env(&PATH_KEY, p.to_string_lossy().as_ref())
101102
} else {
102103
String::new()
103104
}

src/cli/direnv/envrc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use xx::file;
66

77
use crate::config::Config;
88
use crate::env;
9+
use crate::env::PATH_KEY;
910
use crate::hash::hash_to_str;
1011
use crate::toolset::ToolsetBuilder;
1112

@@ -35,7 +36,7 @@ impl Envrc {
3536
writeln!(file, "watch_file {}", cf.to_string_lossy())?;
3637
}
3738
for (k, v) in ts.env(config)? {
38-
if k == "PATH" {
39+
if k == *PATH_KEY {
3940
writeln!(file, "PATH_add {}", v)?;
4041
} else {
4142
writeln!(

src/cli/hook_env.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use itertools::Itertools;
88

99
use crate::config::{Config, Settings};
1010
use crate::direnv::DirenvDiff;
11-
use crate::env::{TERM_WIDTH, __MISE_DIFF};
11+
use crate::env::{PATH_KEY, TERM_WIDTH, __MISE_DIFF};
1212
use crate::env_diff::{EnvDiff, EnvDiffOperation};
1313
use crate::shell::{get_shell, ShellType};
1414
use crate::toolset::{Toolset, ToolsetBuilder};
@@ -42,7 +42,7 @@ impl HookEnv {
4242
let shell = get_shell(self.shell).expect("no shell provided, use `--shell=zsh`");
4343
miseprint!("{}", hook_env::clear_old_env(&*shell))?;
4444
let mut env = ts.env(&config)?;
45-
let env_path = env.remove("PATH");
45+
let env_path = env.remove(&*PATH_KEY);
4646
let mut diff = EnvDiff::new(&env::PRISTINE_ENV, env);
4747
let mut patches = diff.to_patches();
4848

@@ -112,7 +112,7 @@ impl HookEnv {
112112
.into_iter()
113113
.filter(|p| !p.is_empty())
114114
.join(":");
115-
let mut ops = vec![EnvDiffOperation::Add("PATH".into(), new_path)];
115+
let mut ops = vec![EnvDiffOperation::Add(PATH_KEY.to_string(), new_path)];
116116

117117
if let Some(input) = env::DIRENV_DIFF.deref() {
118118
match self.update_direnv_diff(input, installs, to_remove) {

src/cmd.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use signal_hook::iterator::Signals;
1717

1818
use crate::config::Settings;
1919
use crate::env;
20+
use crate::env::PATH_KEY;
2021
use crate::errors::Error::ScriptFailed;
2122
use crate::file::display_path;
2223
use crate::ui::progress_report::SingleReport;
@@ -182,14 +183,14 @@ impl<'a> CmdLineRunner<'a> {
182183

183184
pub fn prepend_path(mut self, paths: Vec<PathBuf>) -> eyre::Result<Self> {
184185
let existing = self
185-
.get_env("PATH")
186+
.get_env(&PATH_KEY)
186187
.map(|c| c.to_owned())
187-
.unwrap_or_else(|| env::var_os("PATH").unwrap());
188+
.unwrap_or_else(|| env::var_os(&*PATH_KEY).unwrap());
188189
let paths = paths
189190
.into_iter()
190191
.chain(env::split_paths(&existing))
191192
.collect::<Vec<_>>();
192-
self.cmd.env("PATH", env::join_paths(paths)?);
193+
self.cmd.env(&*PATH_KEY, env::join_paths(paths)?);
193194
Ok(self)
194195
}
195196

src/config/env_directive.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use indexmap::IndexMap;
88
use crate::cmd::CmdLineRunner;
99
use crate::config::config_file::trust_check;
1010
use crate::config::{Config, Settings};
11+
use crate::env::PATH_KEY;
1112
use crate::env_diff::{EnvDiff, EnvDiffOperation};
1213
use crate::file::display_path;
1314
use crate::tera::{get_tera, BASE_CONTEXT};
@@ -172,13 +173,13 @@ impl EnvResults {
172173
let path = ts
173174
.list_paths()
174175
.into_iter()
175-
.chain(env::split_paths(&env_vars["PATH"]))
176+
.chain(env::split_paths(&env_vars[&*PATH_KEY]))
176177
.collect::<Vec<_>>();
177178
let cmd = CmdLineRunner::new("python3")
178179
.args(["-m", "venv", &venv.to_string_lossy()])
179180
.envs(&env_vars)
180181
.env(
181-
"PATH",
182+
PATH_KEY.to_string(),
182183
env::join_paths(&path)?.to_string_lossy().to_string(),
183184
);
184185
if ts

src/direnv.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::fmt::{Display, Formatter};
44
use std::io::Write;
55
use std::path::{Path, PathBuf};
66

7+
use crate::env::PATH_KEY;
78
use base64::prelude::*;
89
use eyre::Result;
910
use flate2::write::{ZlibDecoder, ZlibEncoder};
@@ -33,15 +34,15 @@ impl DirenvDiff {
3334
}
3435

3536
pub fn new_path(&self) -> Vec<PathBuf> {
36-
let path = self.new.get("PATH");
37+
let path = self.new.get(&*PATH_KEY);
3738
match path {
3839
Some(path) => split_paths(path).collect(),
3940
None => vec![],
4041
}
4142
}
4243

4344
pub fn old_path(&self) -> Vec<PathBuf> {
44-
let path = self.old.get("PATH");
45+
let path = self.old.get(&*PATH_KEY);
4546
match path {
4647
Some(path) => split_paths(path).collect(),
4748
None => vec![],
@@ -59,10 +60,14 @@ impl DirenvDiff {
5960
old.insert(0, path.into());
6061
new.insert(0, path.into());
6162

62-
self.old
63-
.insert("PATH".into(), join_paths(&old)?.into_string().unwrap());
64-
self.new
65-
.insert("PATH".into(), join_paths(&new)?.into_string().unwrap());
63+
self.old.insert(
64+
PATH_KEY.to_string(),
65+
join_paths(&old)?.into_string().unwrap(),
66+
);
67+
self.new.insert(
68+
PATH_KEY.to_string(),
69+
join_paths(&new)?.into_string().unwrap(),
70+
);
6671

6772
Ok((old, new))
6873
}
@@ -78,10 +83,14 @@ impl DirenvDiff {
7883
old.iter().position(|p| p == path).map(|i| old.remove(i));
7984
new.iter().position(|p| p == path).map(|i| new.remove(i));
8085

81-
self.old
82-
.insert("PATH".into(), join_paths(&old)?.into_string().unwrap());
83-
self.new
84-
.insert("PATH".into(), join_paths(&new)?.into_string().unwrap());
86+
self.old.insert(
87+
PATH_KEY.to_string(),
88+
join_paths(&old)?.into_string().unwrap(),
89+
);
90+
self.new.insert(
91+
PATH_KEY.to_string(),
92+
join_paths(&new)?.into_string().unwrap(),
93+
);
8594

8695
Ok((old, new))
8796
}

src/env.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::collections::{HashMap, HashSet};
22
pub use std::env::*;
33
use std::path;
44
use std::path::PathBuf;
5+
use std::string::ToString;
56
use std::sync::RwLock;
67
use std::time::Duration;
78

@@ -134,11 +135,18 @@ pub static PREFER_STALE: Lazy<bool> = Lazy::new(|| prefer_stale(&ARGS.read().unw
134135
/// essentially, this is whether we show spinners or build output on runtime install
135136
pub static PRISTINE_ENV: Lazy<HashMap<String, String>> =
136137
Lazy::new(|| get_pristine_env(&__MISE_DIFF, vars().collect()));
137-
pub static PATH: Lazy<Vec<PathBuf>> = Lazy::new(|| match PRISTINE_ENV.get("PATH") {
138+
pub static PATH_KEY: Lazy<String> = Lazy::new(|| {
139+
vars()
140+
.map(|(k, _)| k)
141+
.find_or_first(|k| k.to_uppercase() == "PATH")
142+
.map(|k| k.to_string())
143+
.unwrap_or("PATH".into())
144+
});
145+
pub static PATH: Lazy<Vec<PathBuf>> = Lazy::new(|| match PRISTINE_ENV.get(&*PATH_KEY) {
138146
Some(path) => split_paths(path).collect(),
139147
None => vec![],
140148
});
141-
pub static PATH_NON_PRISTINE: Lazy<Vec<PathBuf>> = Lazy::new(|| match var("PATH") {
149+
pub static PATH_NON_PRISTINE: Lazy<Vec<PathBuf>> = Lazy::new(|| match var(&*PATH_KEY) {
142150
Ok(ref path) => split_paths(path).collect(),
143151
Err(_) => vec![],
144152
});
@@ -306,7 +314,7 @@ fn get_pristine_env(
306314
let mut env = apply_patches(&orig_env, &patches);
307315

308316
// get the current path as a vector
309-
let path = match env.get("PATH") {
317+
let path = match env.get(&*PATH_KEY) {
310318
Some(path) => split_paths(path).collect(),
311319
None => vec![],
312320
};
@@ -321,7 +329,7 @@ fn get_pristine_env(
321329

322330
// put the pristine PATH back into the environment
323331
env.insert(
324-
"PATH".into(),
332+
PATH_KEY.to_string(),
325333
join_paths(path).unwrap().to_string_lossy().to_string(),
326334
);
327335
env

src/env_diff.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use flate2::Compression;
1111
use itertools::Itertools;
1212
use serde_derive::{Deserialize, Serialize};
1313

14+
use crate::env::PATH_KEY;
1415
use crate::{cmd, file};
1516

1617
#[derive(Default, Serialize, Deserialize)]
@@ -161,7 +162,7 @@ fn valid_key(k: &str) -> bool {
161162
k.is_empty()
162163
|| k == "_"
163164
|| k == "SHLVL"
164-
|| k == "PATH"
165+
|| k == *PATH_KEY
165166
|| k == "PWD"
166167
|| k == "OLDPWD"
167168
|| k == "HOME"

src/fake_asdf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::env::{join_paths, split_paths};
1+
use std::env::{join_paths, split_paths, PATH_KEY};
22
use std::fs;
33
use std::os::unix::fs::PermissionsExt;
44
use std::path::PathBuf;
@@ -34,7 +34,7 @@ pub fn setup() -> color_eyre::Result<PathBuf> {
3434
}
3535

3636
pub fn get_path_with_fake_asdf() -> String {
37-
let mut path = split_paths(&env::var_os("PATH").unwrap_or_default()).collect::<Vec<_>>();
37+
let mut path = split_paths(&env::var_os(&*PATH_KEY).unwrap_or_default()).collect::<Vec<_>>();
3838
match setup() {
3939
Ok(fake_asdf_path) => {
4040
path.insert(0, fake_asdf_path);

src/fake_asdf_windows.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::env::{join_paths, split_paths};
22
use std::path::PathBuf;
33

44
use crate::env;
5+
use crate::env::PATH_KEY;
56

67
#[cfg(windows)]
78
pub fn setup() -> color_eyre::Result<PathBuf> {
@@ -10,7 +11,7 @@ pub fn setup() -> color_eyre::Result<PathBuf> {
1011
}
1112

1213
pub fn get_path_with_fake_asdf() -> String {
13-
let mut path = split_paths(&env::var_os("PATH").unwrap_or_default()).collect::<Vec<_>>();
14+
let mut path = split_paths(&env::var_os(&*PATH_KEY).unwrap_or_default()).collect::<Vec<_>>();
1415
match setup() {
1516
Ok(fake_asdf_path) => {
1617
path.insert(0, fake_asdf_path);

0 commit comments

Comments
 (0)