Skip to content

Commit

Permalink
fix: make hook-env compatible with zsh auto_name_dirs (#3366)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx authored Dec 5, 2024
1 parent 00c1687 commit c8672af
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/cli/hook_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,18 @@ impl HookEnv {
))
}

/// set the directory where hook-env was last run from
/// prefixed with ":" so it does not conflict with zsh's auto_name_dirs feature
fn build_dir_operation(&self) -> Result<EnvDiffOperation> {
Ok(EnvDiffOperation::Add(
"__MISE_DIR".into(),
dirs::CWD
.as_ref()
.map(|p| p.to_string_lossy().to_string())
.unwrap_or_default(),
format!(
":{}",
dirs::CWD
.as_ref()
.map(|p| p.to_string_lossy().to_string())
.unwrap_or_default()
),
))
}

Expand Down
8 changes: 7 additions & 1 deletion src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,13 @@ pub static MISE_TIMINGS: Lazy<u8> = Lazy::new(|| var_u8("MISE_TIMINGS"));
pub static MISE_PID: Lazy<String> = Lazy::new(|| process::id().to_string());
pub static __MISE_SCRIPT: Lazy<bool> = Lazy::new(|| var_is_true("__MISE_SCRIPT"));
pub static __MISE_DIFF: Lazy<EnvDiff> = Lazy::new(get_env_diff);
pub static __MISE_DIR: Lazy<Option<PathBuf>> = Lazy::new(|| var_path("__MISE_DIR"));
/// the directory where hook-env was last run from
/// prefixed with ":" so it does not conflict with zsh's auto_name_dirs feature
pub static __MISE_DIR: Lazy<Option<PathBuf>> = Lazy::new(|| {
var("__MISE_DIR")
.map(|d| PathBuf::from(d.strip_prefix(":").unwrap_or(&d)))
.ok()
});
pub static __MISE_ORIG_PATH: Lazy<Option<String>> = Lazy::new(|| var("__MISE_ORIG_PATH").ok());
pub static __MISE_WATCH: Lazy<Option<HookEnvWatches>> = Lazy::new(|| match var("__MISE_WATCH") {
Ok(raw) => deserialize_watches(raw)
Expand Down

0 comments on commit c8672af

Please sign in to comment.