Skip to content

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

Prefix shell integration with `command` to prevent alias loops

Maximilian Roos38e4e15bc938
diff --git a/src/shell.rs b/src/shell.rs
index 34dfe9ae6..a44ddf293 100644
--- a/src/shell.rs
+++ b/src/shell.rs
@@ -96,20 +96,20 @@ impl Shell {
match self {
Self::Bash | Self::Zsh | Self::Oil => {
format!(
- "if command -v {} >/dev/null 2>&1; then eval \"$({} init {})\"; fi",
+ "if command -v {} >/dev/null 2>&1; then eval \"$(command {} init {})\"; fi",
cmd_prefix, cmd_prefix, self
)
}
Self::Fish => {
format!(
- "if type -q {}; {} init {} | source; end",
+ "if type -q {}; command {} init {} | source; end",
cmd_prefix, cmd_prefix, self
)
}
Self::Nushell => {
// Use user's home directory cache instead of shared /tmp for security
format!(
- "if (which {} | is-not-empty) {{ let tmpfile = ($env.HOME | path join \".cache\" \"nushell-{}-init.nu\"); {} init {} | save --force $tmpfile; source $tmpfile }}",
+ "if (which {} | is-not-empty) {{ let tmpfile = ($env.HOME | path join \".cache\" \"nushell-{}-init.nu\"); ^{} init {} | save --force $tmpfile; source $tmpfile }}",
cmd_prefix, cmd_prefix, cmd_prefix, self
)
}
@@ -121,7 +121,7 @@ impl Shell {
}
Self::Elvish => {
format!(
- "if (has-external {}) {{ eval ({} init {}) }}",
+ "if (has-external {}) {{ eval (e:{} init {}) }}",
cmd_prefix, cmd_prefix, self
)
}
diff --git a/tests/integration_tests/configure_shell.rs b/tests/integration_tests/configure_shell.rs
index 1fd07c387..88f980107 100644
--- a/tests/integration_tests/configure_shell.rs
+++ b/tests/integration_tests/configure_shell.rs
@@ -32,7 +32,7 @@ fn test_configure_shell_with_yes() {
exit_code: 0
----- stdout -----
✅ Added zsh [TEMP_HOME]/.zshrc
-   if command -v wt >/dev/null 2>&1; then eval "$(wt init zsh)"; fi
+   if command -v wt >/dev/null 2>&1; then eval "$(command wt init zsh)"; fi
✅ Configured 1 shell
@@ -44,7 +44,7 @@ fn test_configure_shell_with_yes() {
// Verify the file was modified
let content = fs::read_to_string(&zshrc_path).unwrap();
- assert!(content.contains("eval \"$(wt init zsh)\""));
+ assert!(content.contains("eval \"$(command wt init zsh)\""));
}
/// Test configure-shell with specific shell
@@ -77,7 +77,7 @@ fn test_configure_shell_specific_shell() {
exit_code: 0
----- stdout -----
✅ Added zsh [TEMP_HOME]/.zshrc
-   if command -v wt >/dev/null 2>&1; then eval "$(wt init zsh)"; fi
+   if command -v wt >/dev/null 2>&1; then eval "$(command wt init zsh)"; fi
✅ Configured 1 shell
@@ -89,7 +89,7 @@ fn test_configure_shell_specific_shell() {
// Verify the file was modified
let content = fs::read_to_string(&zshrc_path).unwrap();
- assert!(content.contains("eval \"$(wt init zsh)\""));
+ assert!(content.contains("eval \"$(command wt init zsh)\""));
}
/// Test configure-shell when line already exists
@@ -102,7 +102,7 @@ fn test_configure_shell_already_exists() {
let zshrc_path = temp_home.path().join(".zshrc");
fs::write(
&zshrc_path,
- "# Existing config\nif command -v wt >/dev/null 2>&1; then eval \"$(wt init zsh)\"; fi\n",
+ "# Existing config\nif command -v wt >/dev/null 2>&1; then eval \"$(command wt init zsh)\"; fi\n",
)
.unwrap();
@@ -163,7 +163,7 @@ fn test_configure_shell_fish() {
exit_code: 0
----- stdout -----
✅ Created fish [TEMP_HOME]/.config/fish/conf.d/wt.fish
-   if type -q wt; wt init fish | source; end
+   if type -q wt; command wt init fish | source; end
✅ Configured 1 shell
@@ -179,7 +179,7 @@ fn test_configure_shell_fish() {
let content = fs::read_to_string(&fish_config).unwrap();
assert!(
- content.trim() == "if type -q wt; wt init fish | source; end",
+ content.trim() == "if type -q wt; command wt init fish | source; end",
"Should contain conditional wrapper: {}",
content
);
@@ -251,9 +251,9 @@ fn test_configure_shell_multiple_configs() {
exit_code: 0
----- stdout -----
✅ Added bash [TEMP_HOME]/.bash_profile
-   if command -v wt >/dev/null 2>&1; then eval "$(wt init bash)"; fi
+   if command -v wt >/dev/null 2>&1; then eval "$(command wt init bash)"; fi
✅ Added zsh [TEMP_HOME]/.zshrc
-   if command -v wt >/dev/null 2>&1; then eval "$(wt init zsh)"; fi
+   if command -v wt >/dev/null 2>&1; then eval "$(command wt init zsh)"; fi
✅ Configured 2 shells
@@ -266,13 +266,13 @@ fn test_configure_shell_multiple_configs() {
// Verify both files were modified
let bash_content = fs::read_to_string(&bash_config_path).unwrap();
assert!(
- bash_content.contains("eval \"$(wt init bash)\""),
+ bash_content.contains("eval \"$(command wt init bash)\""),
"Bash config should be updated"
);
let zsh_content = fs::read_to_string(&zshrc_path).unwrap();
assert!(
- zsh_content.contains("eval \"$(wt init zsh)\""),
+ zsh_content.contains("eval \"$(command wt init zsh)\""),
"Zsh config should be updated"
);
}
@@ -287,7 +287,7 @@ fn test_configure_shell_mixed_states() {
let bash_config_path = temp_home.path().join(".bash_profile");
fs::write(
&bash_config_path,
- "# Existing config\nif command -v wt >/dev/null 2>&1; then eval \"$(wt init bash)\"; fi\n",
+ "# Existing config\nif command -v wt >/dev/null 2>&1; then eval \"$(command wt init bash)\"; fi\n",
)
.unwrap();
@@ -313,9 +313,9 @@ fn test_configure_shell_mixed_states() {
exit_code: 0
----- stdout -----
⚪ Already configured bash [TEMP_HOME]/.bash_profile
-   if command -v wt >/dev/null 2>&1; then eval "$(wt init bash)"; fi
+   if command -v wt >/dev/null 2>&1; then eval "$(command wt init bash)"; fi
✅ Added zsh [TEMP_HOME]/.zshrc
-   if command -v wt >/dev/null 2>&1; then eval "$(wt init zsh)"; fi
+   if command -v wt >/dev/null 2>&1; then eval "$(command wt init zsh)"; fi
✅ Configured 1 shell
@@ -336,7 +336,7 @@ fn test_configure_shell_mixed_states() {
// Verify zsh was modified
let zsh_content = fs::read_to_string(&zshrc_path).unwrap();
assert!(
- zsh_content.contains("eval \"$(wt init zsh)\""),
+ zsh_content.contains("eval \"$(command wt init zsh)\""),
"Zsh config should be updated"
);
}