Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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_string_lossy();

let args: Vec<String> = env::args().skip(1).collect();

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

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.

Using env::args() forces UTF-8 String arguments and can be lossy/non-representable on some platforms; Command is designed to work with OS-native strings. Prefer env::args_os().skip(1) and pass those directly to .args(...) (and consider keeping tool as an OsString/OsStr as well) to avoid any encoding edge cases.

Suggested change
.to_string_lossy();
let args: Vec<String> = env::args().skip(1).collect();
let status = Command::new("mise")
.arg("x")
.arg("--")
.arg(tool.as_ref())
.args(&args)
.to_os_string();
let args = env::args_os().skip(1);
let status = Command::new("mise")
.arg("x")
.arg("--")
.arg(&tool)
.args(args)

Copilot uses AI. Check for mistakes.
.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
11 changes: 11 additions & 0 deletions e2e-win/shim.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ Describe 'shim_mode' {
(Get-Item -Path (Join-Path -Path $shimPath -ChildPath go.cmd)).LinkType | Should -Be $null
}

It 'run on exe' {
changeShimMode "exe"

mise x go@1.23.3 -- where go
mise x go@1.23.3 -- go version | Should -BeLike "go version go1.23.3 windows/*"

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.

mise x ... -- where go doesn’t assert anything, and PowerShell won’t fail the test automatically if where.exe returns a non-zero exit code. Capture and assert the output (e.g., that it contains the shim path and ends with go.exe) and/or assert $LASTEXITCODE -eq 0 so the test actually verifies the "exe" shim behavior it’s meant to cover.

Copilot uses AI. Check for mistakes.

$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
63 changes: 61 additions & 2 deletions src/shims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,14 @@ 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 {
let shim_mode = if cfg!(windows) {
Settings::get().windows_shim_mode.clone()
} else {
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 +149,56 @@ pub async fn reshim(config: &Arc<Config>, ts: &Toolset, force: bool) -> Result<(
Ok(())
}

#[cfg(windows)]
fn find_mise_shim_bin(mise_bin: &Path) -> Result<PathBuf> {
// Look next to the mise binary first
if let Some(parent) = mise_bin.parent() {
let candidate = parent.join("mise-shim.exe");
if candidate.exists() {

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.

candidate.exists() will also return true for directories; returning a directory path here will make fs::copy fail later with a less-direct error. Prefer checking candidate.is_file() (or metadata + is_file) so the failure mode is accurate and earlier.

Suggested change
if candidate.exists() {
if candidate.is_file() {

Copilot uses AI. Check for mistakes.
return Ok(candidate);
}
}
// Fall back to searching PATH
if let Some(found) = file::which("mise-shim").or_else(|| file::which("mise-shim.exe")) {

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.

medium

The which crate, which file::which seems to wrap, automatically handles executable extensions like .exe on Windows. Therefore, calling file::which("mise-shim.exe") in the or_else is redundant. You can simplify this to a single call to file::which("mise-shim").

Suggested change
if let Some(found) = file::which("mise-shim").or_else(|| file::which("mise-shim.exe")) {
if let Some(found) = file::which("mise-shim") {

return Ok(found);
}
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
bail!(
"mise-shim.exe not found. It should be located next to mise.exe at {}.\n\
You may need to reinstall mise or switch to a different windows_shim_mode.",
display_path(mise_bin)
);
}

#[cfg(windows)]
fn add_shim(mise_bin: &Path, symlink_path: &Path, shim: &str) -> Result<()> {
match Settings::get().windows_shim_mode.as_ref() {
"exe" => {
let mise_shim_bin = find_mise_shim_bin(mise_bin)?;
let shim_name = shim.trim_end_matches(".exe");
// Copy mise-shim.exe as <tool>.exe
fs::copy(&mise_shim_bin, symlink_path.with_extension("exe")).wrap_err_with(|| {
eyre!(
"Failed to copy {} to {}",
display_path(&mise_shim_bin),
display_path(symlink_path)
)
})?;
// Also create extensionless bash script for Git Bash/Cygwin
file::write(
symlink_path.with_extension(""),
formatdoc! {r#"
#!/bin/bash

exec mise x -- {shim_name} "$@"
"#},
)

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.

The copy operation writes to symlink_path.with_extension("exe"), but the error message reports the destination as display_path(symlink_path), which can be misleading (especially when symlink_path is extensionless). Use the same computed destination path in both the actual copy and the error message.

Copilot uses AI. Check for mistakes.
.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 @@ -303,6 +356,12 @@ async fn get_desired_shims(config: &Arc<Config>, toolset: &Toolset) -> Result<Ha
"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