Skip to content

Conversation

@jdx
Copy link
Owner

@jdx jdx commented Oct 31, 2025

Summary

When mise activate is called multiple times in a shell rc file, each call now resets __MISE_ORIG_PATH to the current PATH. This allows mise tools to move to the front of the "locked in" user path additions.

Problem

Previously, when activate was called multiple times:

  1. First mise activate__MISE_ORIG_PATH=A, PATH=mise_tools:A
  2. User adds custom path B → PATH=B:mise_tools:A
  3. Second mise activate__MISE_ORIG_PATH still=A, PATH=B:mise_tools:A (mise tools stay in place)

Result: mise tools didn't move to the front of the original path when activate was called again.

Solution

Now, each activation unconditionally resets __MISE_ORIG_PATH to the current PATH:

  1. First mise activate__MISE_ORIG_PATH=A, PATH=mise_tools:A
  2. User adds custom path B → PATH=B:mise_tools:A
  3. Second mise activate__MISE_ORIG_PATH=B:mise_tools:A, then hook-env runs → PATH=mise_tools:B:A

This "locks in" user additions at each activation point. The most recent custom additions stay at the front, but mise tools move to be immediately after them (and before older additions).

Example Behavior

# .bashrc
eval "$(mise activate bash)"  # A: __MISE_ORIG_PATH=original_path
export PATH="/custom1:$PATH"   # PATH=custom1:mise_tools:original_path
eval "$(mise activate bash)"  # B: __MISE_ORIG_PATH=custom1:mise_tools:original_path, then PATH=mise_tools:custom1:original_path
export PATH="/custom2:$PATH"   # PATH=custom2:mise_tools:custom1:original_path

Result: custom2:mise_tools:custom1:original_path - newest additions stay front, mise tools move to front of "locked in" path.

Changes

  • All shells (bash, fish, zsh, pwsh) now unconditionally set __MISE_ORIG_PATH="$PATH" on each activation
  • Added E2E test test_activate_multiple to verify the behavior
  • Updated snapshots to reflect simpler activation code

🤖 Generated with Claude Code


Note

Repeated activation keeps user-added PATH entries at the front without duplication; deactivation removes mise-managed env/paths while preserving user/pristine entries, with new e2e coverage.

  • Shell activation/deactivation:
    • Activation now emits a deactivation script first and sets __MISE_ORIG_PATH only if unset across bash, zsh, fish, pwsh, nu, xonsh, elvish.
    • src/cli/deactivate.rs: use build_deactivation_script(...) and also unset __MISE_ORIG_PATH.
  • PATH/env handling:
    • hook_env::build_path_operations: compute pre by excluding original and previous mise-managed paths; preserves genuine user additions; filters installs to avoid duplicates.
    • hook_env::clear_old_env + new compute_deactivated_path: rebuild PATH on deactivate to drop mise paths while retaining user/pristine entries (special-case fish PATH ops).
  • Tests & snapshots:
    • Add e2e/cli/test_activate_multiple and e2e/cli/test_deactivate.
    • Update activation snapshots for shells to reflect conditional __MISE_ORIG_PATH and deactivation prelude.

Written by Cursor Bugbot for commit 54df803. This will update automatically on new commits. Configure here.

Copilot AI review requested due to automatic review settings October 31, 2025 10:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements PATH reset functionality for multiple mise activations, preventing PATH corruption when mise activate is called multiple times in shell configuration files. The change ensures that subsequent activations reset PATH to the original state before applying mise modifications.

Key Changes:

  • Adds conditional logic to check for existing __MISE_ORIG_PATH variable across all supported shells
  • Resets PATH to original state on subsequent activations instead of stacking modifications
  • Preserves original PATH value for future resets

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/shell/bash.rs Adds PATH reset logic using bash conditional syntax
src/shell/fish.rs Adds PATH reset logic using fish shell conditional syntax
src/shell/zsh.rs Adds PATH reset logic using zsh conditional syntax
src/shell/pwsh.rs Adds PATH reset logic using PowerShell conditional syntax
src/shell/snapshots/*.snap Updates test snapshots to reflect new activation behavior
e2e/cli/test_activate_multiple Adds end-to-end test for multiple activation scenario

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

export __MISE_ORIG_PATH="$PATH"
export __MISE_ZSH_PRECMD_RUN=0
if [ -z "${{__MISE_ORIG_PATH:-}}" ]; then
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double curly braces in variable expansion will be interpreted literally by the shell. Should use single curly braces: ${__MISE_ORIG_PATH:-}

Suggested change
if [ -z "${{__MISE_ORIG_PATH:-}}" ]; then
if [ -z "${__MISE_ORIG_PATH:-}" ]; then

Copilot uses AI. Check for mistakes.
export MISE_SHELL=bash
export __MISE_ORIG_PATH="$PATH"
if [ -z "${{__MISE_ORIG_PATH:-}}" ]; then
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double curly braces in variable expansion will be interpreted literally by the shell. Should use single curly braces: ${__MISE_ORIG_PATH:-}

Copilot uses AI. Check for mistakes.
cursor[bot]

This comment was marked as outdated.

@jdx jdx force-pushed the 10-31-feat_activate_reset_path_when_activate_is_called_multiple_times branch 2 times, most recently from ce13425 to 3e818ac Compare October 31, 2025 10:43
@github-actions
Copy link

github-actions bot commented Oct 31, 2025

Hyperfine Performance

mise x -- echo

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2025.10.21 x -- echo 19.4 ± 0.6 18.7 27.8 1.00
mise x -- echo 19.8 ± 0.5 18.9 26.0 1.02 ± 0.04

mise env

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2025.10.21 env 18.6 ± 0.4 17.9 22.8 1.00
mise env 19.0 ± 0.9 18.1 29.7 1.02 ± 0.05

mise hook-env

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2025.10.21 hook-env 18.8 ± 0.3 18.0 20.3 1.00
mise hook-env 19.2 ± 0.4 18.3 20.4 1.02 ± 0.03

mise ls

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2025.10.21 ls 16.5 ± 0.5 15.7 23.4 1.00
mise ls 17.1 ± 0.6 16.1 25.4 1.03 ± 0.05

xtasks/test/perf

Command mise-2025.10.21 mise Variance
install (cached) 110ms 111ms +0%
ls (cached) 67ms 67ms +0%
bin-paths (cached) 72ms 76ms -5%
task-ls (cached) 436ms 487ms -10%

cursor[bot]

This comment was marked as outdated.

@jdx jdx force-pushed the 10-31-feat_activate_reset_path_when_activate_is_called_multiple_times branch 8 times, most recently from 745cc24 to 33484d0 Compare October 31, 2025 20:05
@jdx jdx changed the title feat(activate): reset PATH when activate is called multiple times fix(activate): reset PATH when activate is called multiple times Oct 31, 2025
When mise activate is called multiple times in a shell rc file, the second
call now resets PATH to the original state before applying mise modifications.

This prevents PATH corruption when users have multiple activate calls in their
shell configuration, ensuring each activation behaves as if it's the first.

Changes:
- bash: Check if __MISE_ORIG_PATH exists, reset PATH if it does
- fish: Check if __MISE_ORIG_PATH exists, reset PATH if it does
- zsh: Check if __MISE_ORIG_PATH exists, reset PATH if it does
- pwsh: Check if __MISE_ORIG_PATH exists, reset PATH if it does
- Added E2E test for multiple activate calls

The feature ensures that calling activate a second time will:
1. Reset PATH to __MISE_ORIG_PATH (the original PATH from first activation)
2. Apply mise modifications on top of the clean slate
3. Preserve __MISE_ORIG_PATH for potential future activations
@jdx jdx force-pushed the 10-31-feat_activate_reset_path_when_activate_is_called_multiple_times branch from 33484d0 to caa7a95 Compare October 31, 2025 20:28
@jdx jdx force-pushed the 10-31-feat_activate_reset_path_when_activate_is_called_multiple_times branch from 0149c4b to 54df803 Compare October 31, 2025 21:07
@jdx jdx enabled auto-merge (squash) October 31, 2025 21:15
@jdx jdx merged commit 3b31456 into main Oct 31, 2025
28 checks passed
@jdx jdx deleted the 10-31-feat_activate_reset_path_when_activate_is_called_multiple_times branch October 31, 2025 21:18
jdx pushed a commit that referenced this pull request Nov 1, 2025
### 🐛 Bug Fixes

- **(activate)** reset PATH when activate is called multiple times by
@jdx in [#6829](#6829)
- **(env)** preserve user-configured PATH entries from env._.path by
@jdx in [#6835](#6835)
- store tool options for all backends in metadata by @roele in
[#6807](#6807)

### 📚 Documentation

- fix usage spec syntax from 'option' to 'flag' by @jdx in
[#6834](#6834)

### 📦️ Dependency Updates

- update ghcr.io/jdx/mise:alpine docker digest to 7351bbe by
@renovate[bot] in [#6826](#6826)
- update ghcr.io/jdx/mise:deb docker digest to 3a847f2 by @renovate[bot]
in [#6828](#6828)
- update ghcr.io/jdx/mise:copr docker digest to 546dffb by
@renovate[bot] in [#6827](#6827)
- pin jdx/mise-action action to e3d7b8d by @renovate[bot] in
[#6825](#6825)
jdx pushed a commit that referenced this pull request Nov 18, 2025
… operations (#6994)

- addresses the unexpected behaviour discussed here:
#6876
- previously, work was done to have `mise` reverse the changes it made
to the environment variables: #6829
- however, for nushell, this resulted in the raw operations CSV text
becoming part of the activation script, which is not valid nushell
syntax
- this PR wraps the raw operations CSV text in quotes to make it a
string literal, and then passes it through `| parse env | update-env`
just as with other places in the nushell script that make use of the raw
operations CSV text
- in order for that work, the `parse env` and `update-env` functions
were re-ordered to always be above the deactivation statements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants