Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"crates/vfox",
"crates/aqua-registry",
"crates/mise-interactive-config",
"crates/mise-shim",
]

[package]
Expand Down
15 changes: 15 additions & 0 deletions crates/mise-shim/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "mise-shim"
version = "2026.2.5"
edition = "2024"
license = "MIT"
description = "Native executable shim for mise"
homepage = "https://github.com/jdx/mise"
repository = "https://github.com/jdx/mise"

[[bin]]
name = "mise-shim"
path = "src/main.rs"

[dependencies]
# zero external dependencies — only std
22 changes: 22 additions & 0 deletions crates/mise-shim/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2026 Jeff Dickey
Copyright (c) 2026 Jan Killian

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
37 changes: 37 additions & 0 deletions crates/mise-shim/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Based on https://github.com/iki/mise-shim by Jan Killian (MIT License)

use std::env;
use std::process::{Command, exit};

fn main() {
let exe = env::current_exe().unwrap_or_else(|e| {
eprintln!("mise-shim: failed to determine executable path: {e}");
exit(1);
});
let tool = exe
.file_stem()
.unwrap_or_else(|| {
eprintln!("mise-shim: failed to determine tool name from executable path");
exit(1);
})
.to_os_string();

let args = env::args_os().skip(1);

let status = Command::new("mise")
.arg("x")
.arg("--")
.arg(&tool)
.args(args)
.status();

match status {
Ok(s) => exit(s.code().unwrap_or(1)),
Err(e) => {
eprintln!("mise-shim: failed to execute mise: {e}");
eprintln!("Ensure `mise` is installed and available on your PATH.");
eprintln!("See https://mise.jdx.dev for installation instructions.");
exit(1);
}
}
}
2 changes: 1 addition & 1 deletion docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ It handles daemon management with features like automatic restarts on failure, s

In VSCode, many extensions will throw an "error spawn EINVAL" due to a [Node.js security fix](https://nodejs.org/en/blog/vulnerability/april-2024-security-releases-2#command-injection-via-args-parameter-of-child_processspawn-without-shell-option-enabled-on-windows-cve-2024-27980---high).

You can change [windows_shim_mode](https://mise.jdx.dev/configuration/settings.html#windows_shim_mode) to `hardlink` or `symlink`
The default `exe` shim mode should resolve this. If you're using an older mode, you can change [windows_shim_mode](https://mise.jdx.dev/configuration/settings.html#windows_shim_mode) to `exe`, `hardlink`, or `symlink`.

## How does mise versioning work?

Expand Down
13 changes: 13 additions & 0 deletions e2e-win/shim.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ Describe 'shim_mode' {
(Get-Item -Path (Join-Path -Path $shimPath -ChildPath go.cmd)).LinkType | Should -Be $null
}

It 'run on exe' {
changeShimMode "exe"

$wherePath = mise x go@1.23.3 -- where go
$LASTEXITCODE | Should -Be 0
$wherePath | Should -BeLike "*go.exe"
mise x go@1.23.3 -- go version | Should -BeLike "go version go1.23.3 windows/*"

$goShim = Get-Item -Path (Join-Path -Path $shimPath -ChildPath go.exe)
$goShim.LinkType | Should -Be $null
$goShim.Length | Should -BeGreaterThan 0
}

It 'run on hardlink' {
mise settings windows_shim_mode "hardlink"

Expand Down
4 changes: 2 additions & 2 deletions schema/mise.json
Original file line number Diff line number Diff line change
Expand Up @@ -1381,8 +1381,8 @@
}
},
"windows_shim_mode": {
"default": "file",
"description": "Shim file mode for Windows. Options: `file`, `hardlink`, `symlink`.",
"default": "exe",
"description": "Shim file mode for Windows. Options: `exe`, `file`, `hardlink`, `symlink`.",
"type": "string"
},
"yes": {
Expand Down
2 changes: 2 additions & 0 deletions scripts/build-tarball.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ $BaseName = "mise-v$Version-$Env:OS-$Env:ARCH"

# TODO: use "serious" feature
cargo build --release --features rustls-native-roots,openssl/vendored --target "$Target"
cargo build --release -p mise-shim --target "$Target"
mkdir -p dist/mise/bin
cp "target/$Target/release/mise.exe" dist/mise/bin/mise.exe
cp "target/$Target/release/mise-shim.exe" dist/mise/bin/mise-shim.exe
cp README.md dist/mise/README.md
cp LICENSE dist/mise/LICENSE
Set-Location dist
Expand Down
7 changes: 4 additions & 3 deletions settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1763,11 +1763,12 @@ rust_type = "Vec<String>"
type = "ListString"

[windows_shim_mode]
default = "file"
description = "Shim file mode for Windows. Options: `file`, `hardlink`, `symlink`."
default = "exe"
description = "Shim file mode for Windows. Options: `exe`, `file`, `hardlink`, `symlink`."
docs = """
* values:
* `file`: Creates a file with the content `mise exec`.
* `exe`: Copies a native executable shim (`mise-shim.exe`) as `<tool>.exe`. Recommended. Works with all shells, package managers, and `where.exe`. Requires `mise-shim.exe` alongside `mise.exe`.
* `file`: Creates a `.cmd` batch file shim and an extensionless bash script for Git Bash/Cygwin.
* `hardlink`: Uses Windows NTFS Hardlink, required on same filesystems. Need run `mise reshim --force` after upgrade mise.
* `symlink`: Uses Windows NTFS SymbolicLink. Requires Windows Vista or later with admin privileges or enabling "Developer Mode" in Windows 10/11.
"""
Expand Down
95 changes: 89 additions & 6 deletions src/shims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,13 @@ pub async fn reshim(config: &Arc<Config>, ts: &Toolset, force: bool) -> Result<(
let mise_bin = file::which("mise").unwrap_or(env::MISE_BIN.clone());
let mise_bin = mise_bin.absolutize()?; // relative paths don't work as shims

let is_windows_hardlink = cfg!(windows) && Settings::get().windows_shim_mode.eq("hardlink");
if force || is_windows_hardlink {
#[cfg(windows)]
let shim_mode = effective_shim_mode(&mise_bin);
#[cfg(not(windows))]
let shim_mode = String::new();
let is_windows_hardlink_or_exe =
cfg!(windows) && (shim_mode == "hardlink" || shim_mode == "exe");
if force || is_windows_hardlink_or_exe {
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
file::remove_all(*dirs::SHIMS)?;
}
file::create_dir_all(*dirs::SHIMS)?;
Expand Down Expand Up @@ -143,9 +148,72 @@ pub async fn reshim(config: &Arc<Config>, ts: &Toolset, force: bool) -> Result<(
Ok(())
}

#[cfg(windows)]
fn find_mise_shim_bin(mise_bin: &Path) -> Option<PathBuf> {
// Look next to the mise binary first
if let Some(parent) = mise_bin.parent() {
let candidate = parent.join("mise-shim.exe");
if candidate.is_file() {
return Some(candidate);
}
}
// Fall back to searching PATH
file::which("mise-shim.exe")
}

/// Resolve the effective Windows shim mode, falling back to "file" if "exe" is
/// requested but mise-shim.exe is not available.
#[cfg(windows)]
fn effective_shim_mode(mise_bin: &Path) -> String {
let mode = Settings::get().windows_shim_mode.clone();
if mode == "exe" && find_mise_shim_bin(mise_bin).is_none() {
warn!(
"mise-shim.exe not found next to {} or on PATH, falling back to \"file\" shim mode",
display_path(mise_bin)
);
return "file".to_string();
}
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
mode
}

#[cfg(windows)]
fn add_shim(mise_bin: &Path, symlink_path: &Path, shim: &str) -> Result<()> {
match Settings::get().windows_shim_mode.as_ref() {
match effective_shim_mode(mise_bin).as_ref() {
"exe" => {
if symlink_path.extension().and_then(|s| s.to_str()) == Some("exe") {
let mise_shim_bin =
find_mise_shim_bin(mise_bin).ok_or_else(|| eyre!("mise-shim.exe not found"))?;
// Copy mise-shim.exe as <tool>.exe
fs::copy(&mise_shim_bin, symlink_path).wrap_err_with(|| {
eyre!(
"Failed to copy {} to {}",
display_path(&mise_shim_bin),
display_path(symlink_path)
)
})?;
Ok(())
} else {
let shim_name = symlink_path
.file_name()
.unwrap_or_default()
.to_string_lossy();
// Create extensionless bash script for Git Bash/Cygwin
file::write(
symlink_path,
formatdoc! {r#"
#!/bin/bash

exec mise x -- {shim_name} "$@"
"#},
)
.wrap_err_with(|| {
eyre!(
"Failed to create shim script for {}",
display_path(symlink_path)
)
})
}
}
Comment on lines +195 to +229

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The current implementation for the "exe" shim mode is inefficient. It's called for each desired shim file (<tool>.exe and <tool>), but in both cases, it attempts to create both files. This results in redundant file operations. The function should only create the single file specified by its symlink_path argument, depending on whether it's the .exe or the extensionless script.

        "exe" => {
            if symlink_path.extension().and_then(|s| s.to_str()) == Some("exe") {
                let mise_shim_bin = find_mise_shim_bin(mise_bin)?;
                // Copy mise-shim.exe as <tool>.exe
                fs::copy(&mise_shim_bin, symlink_path).wrap_err_with(|| {
                    eyre!(
                        "Failed to copy {} to {}",
                        display_path(&mise_shim_bin),
                        display_path(symlink_path)
                    )
                })
            } else {
                let shim_name = symlink_path.file_name().unwrap().to_string_lossy();
                // Also create extensionless bash script for Git Bash/Cygwin
                file::write(
                    symlink_path,
                    formatdoc! {r#"
        #!/bin/bash

        exec mise x -- {shim_name} "$@"
        "#},
                )
                .wrap_err_with(|| {
                    eyre!(
                        "Failed to create shim script for {}",
                        display_path(symlink_path)
                    )
                })
            }
        }

"file" => {
let shim = shim.trim_end_matches(".cmd");
// write a shim file without extension for use in Git Bash/Cygwin
Expand Down Expand Up @@ -223,7 +291,7 @@ pub async fn get_shim_diffs(
let mise_bin = mise_bin.as_ref();
let (actual_shims, desired_shims) = tokio::join!(
get_actual_shims(mise_bin),
get_desired_shims(config, toolset)
get_desired_shims(config, mise_bin, toolset)
);
let (actual_shims, desired_shims) = (actual_shims?, desired_shims?);
let out: (BTreeSet<String>, BTreeSet<String>) = (
Expand Down Expand Up @@ -287,7 +355,12 @@ fn list_shims() -> Result<HashSet<String>> {
.collect())
}

async fn get_desired_shims(config: &Arc<Config>, toolset: &Toolset) -> Result<HashSet<String>> {
async fn get_desired_shims(
config: &Arc<Config>,
mise_bin: &Path,
toolset: &Toolset,
) -> Result<HashSet<String>> {
let _mise_bin = mise_bin; // used on Windows only
let mut shims = HashSet::new();
for (t, tv) in toolset.list_installed_versions(config).await? {
let bins = list_tool_bins(config, t.clone(), &tv)
Expand All @@ -297,12 +370,22 @@ async fn get_desired_shims(config: &Arc<Config>, toolset: &Toolset) -> Result<Ha
Vec::new()
});
if cfg!(windows) {
#[cfg(windows)]
let shim_mode = effective_shim_mode(_mise_bin);
#[cfg(not(windows))]
let shim_mode = String::new();
shims.extend(bins.into_iter().flat_map(|b| {
let p = PathBuf::from(&b);
match Settings::get().windows_shim_mode.as_ref() {
match shim_mode.as_ref() {
"hardlink" | "symlink" => {
vec![p.with_extension("exe").to_string_lossy().to_string()]
}
"exe" => {
vec![
p.with_extension("exe").to_string_lossy().to_string(),
p.with_extension("").to_string_lossy().to_string(),
]
Comment on lines +402 to +405

Copilot AI Feb 7, 2026

Copy link

Choose a reason for hiding this comment

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

In "exe" mode, add_shim already creates both <tool>.exe and the extensionless bash script. Returning both paths from get_desired_shims() likely causes add_shim to be invoked twice per tool, duplicating file I/O (two copies + two writes) and repeated find_mise_shim_bin() lookups. Consider returning only the .exe path for "exe" mode (and letting add_shim create the extensionless script as it already does), or alternatively adjust add_shim to create only the file corresponding to symlink_path.

Suggested change
vec![
p.with_extension("exe").to_string_lossy().to_string(),
p.with_extension("").to_string_lossy().to_string(),
]
// In "exe" mode, add_shim already creates both <tool>.exe and the
// extensionless shim script. We only need to track the .exe path here
// to avoid invoking add_shim twice for the same tool.
vec![p.with_extension("exe").to_string_lossy().to_string()]

Copilot uses AI. Check for mistakes.
}
"file" => {
vec![
p.with_extension("").to_string_lossy().to_string(),
Expand Down
Loading