Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

fix: preserve .exe suffix in shell function names on Windows (#438)

Maximilian Roosed94a4708534
diff --git a/src/main.rs b/src/main.rs
index d6bbd0d92..d5be8146b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -50,12 +50,13 @@ use worktrunk::HookType;
///
/// Used as the default for `--cmd` in shell integration commands.
/// When invoked as `git-wt`, returns "git-wt"; when invoked as `wt`, returns "wt".
+/// On Windows, strips `.exe` extension — users should use `wt` not `wt.exe` in aliases.
fn binary_name() -> String {
std::env::args()
.next()
.and_then(|arg0| {
std::path::Path::new(&arg0)
- .file_stem() // Use file_stem to strip .exe on Windows
+ .file_stem()
.and_then(|name| name.to_str())
.map(String::from)
})
diff --git a/src/shell.rs b/src/shell.rs
index 326f047eb..ffa803ec6 100644
--- a/src/shell.rs
+++ b/src/shell.rs
@@ -949,6 +949,8 @@ mod tests {
/// `is_shell_integration_line()` can detect.
///
/// This prevents install and detection from drifting out of sync.
+ /// Note: .exe variants are not included because `binary_name()` strips
+ /// the .exe suffix on Windows (MSYS2/Git Bash handles the resolution).
#[rstest]
fn test_config_line_detected_by_is_shell_integration_line(
#[values(Shell::Bash, Shell::Zsh, Shell::Fish, Shell::PowerShell)] shell: Shell,
diff --git a/tests/integration_tests/mod.rs b/tests/integration_tests/mod.rs
index 94e3c48b0..9728a51ca 100644
--- a/tests/integration_tests/mod.rs
+++ b/tests/integration_tests/mod.rs
@@ -44,6 +44,7 @@ pub mod repository;
pub mod security;
pub mod select;
pub mod shell_integration_prompt;
+pub mod shell_integration_windows;
pub mod shell_wrapper;
pub mod spacing_edge_cases;
pub mod statusline;
diff --git a/tests/integration_tests/shell_integration_windows.rs b/tests/integration_tests/shell_integration_windows.rs
new file mode 100644
index 000000000..dd252aa2c
--- /dev/null
+++ b/tests/integration_tests/shell_integration_windows.rs
@@ -0,0 +1,55 @@
+//! Windows-specific shell integration tests.
+//!
+//! These tests verify that shell integration works correctly on Windows.
+//! On Windows, binaries have `.exe` extension but shell integration uses the base name
+//! (e.g., `wt` not `wt.exe`) because MSYS2/Git Bash handles the resolution automatically.
+
+#![cfg(windows)]
+
+use std::process::Command;
+
+/// Verify shell function uses base name (without .exe) on Windows.
+///
+/// When the binary is invoked as `wt.exe`, the generated bash script should:
+/// 1. Define a function named `wt()` (not `wt.exe()`)
+/// 2. Check for `command -v wt` (not `wt.exe`)
+/// 3. Set up completions for `wt`
+///
+/// Users should use `alias wt="wt"` (or just have `wt` in PATH) rather than
+/// `alias wt="wt.exe"`. MSYS2/Git Bash automatically resolves `wt` to `wt.exe`.
+#[test]
+fn test_shell_init_strips_exe_suffix_on_windows() {
+ // Run wt.exe config shell init bash
+ // Note: This command doesn't need a git repo - it just generates shell init code
+ let output = Command::new(env!("CARGO_BIN_EXE_wt"))
+ .args(["config", "shell", "init", "bash"])
+ .output()
+ .expect("Failed to run wt config shell init");
+
+ assert!(output.status.success(), "Command failed: {:?}", output);
+
+ let stdout = String::from_utf8_lossy(&output.stdout);
+
+ // The binary is wt.exe but function should be wt() (base name)
+ assert!(
+ stdout.contains("wt()"),
+ "Expected function definition 'wt()' not found in output.\n\
+ Shell integration should use base name without .exe.\n\
+ Output:\n{}",
+ stdout
+ );
+
+ // Verify command -v check uses base name
+ assert!(
+ stdout.contains("command -v wt"),
+ "Expected 'command -v wt' check not found in output.\nOutput:\n{}",
+ stdout
+ );
+
+ // Should NOT contain .exe in function/command names
+ assert!(
+ !stdout.contains("wt.exe()"),
+ "Function should be 'wt()' not 'wt.exe()'.\nOutput:\n{}",
+ stdout
+ );
+}
diff --git a/tests/snapshots/integration__integration_tests__init__init_bash.snap b/tests/snapshots/integration__integration_tests__init__init_bash.snap
index db72f4580..35f9b3de1 100644
--- a/tests/snapshots/integration__integration_tests__init__init_bash.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_bash.snap
@@ -23,6 +23,7 @@ info:
PATH: "[PATH]"
RUST_LOG: warn
SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
USERPROFILE: "[TEST_HOME]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
diff --git a/tests/snapshots/integration__integration_tests__init__init_fish.snap b/tests/snapshots/integration__integration_tests__init__init_fish.snap
index bb539d5bd..6669cf7d2 100644
--- a/tests/snapshots/integration__integration_tests__init__init_fish.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_fish.snap
@@ -23,6 +23,7 @@ info:
PATH: "[PATH]"
RUST_LOG: warn
SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
USERPROFILE: "[TEST_HOME]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
diff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snap
index 0bbac00b7..9526c954f 100644
--- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap
@@ -23,6 +23,7 @@ info:
PATH: "[PATH]"
RUST_LOG: warn
SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
USERPROFILE: "[TEST_HOME]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"