Skip to content

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

fix(shell): label nu/pwsh as "shell extension & completions" (#2705)

Worktrunk Bot73f7c48500e5
diff --git a/src/commands/config/show.rs b/src/commands/config/show.rs
index 0613e0415..d69c1b7a3 100644
--- a/src/commands/config/show.rs
+++ b/src/commands/config/show.rs
@@ -751,19 +751,6 @@ fn render_fish_legacy_migration(
Ok(())
}
-/// Per-shell label distinguishing bash/zsh (inline completions) from
-/// everyone else (no inline completions: fish ships a separate completion
-/// file; nushell and powershell have no completions). Mirrors
-/// `output::shell_integration::shell_extension_label` and the equivalent
-/// switch in `commands::configure_shell`.
-fn what_label(shell: Shell) -> &'static str {
- if matches!(shell, Shell::Bash | Shell::Zsh) {
- "shell extension & completions"
- } else {
- "shell extension"
- }
-}
-
/// Zsh-only: warn when compinit isn't enabled, since the integration
/// installs completions but they won't load without compinit.
fn render_zsh_compinit_warning(out: &mut String) -> anyhow::Result<()> {
@@ -848,7 +835,7 @@ fn render_already_configured(
) -> anyhow::Result<()> {
let shell = result.shell;
let path = format_path_for_display(&result.path);
- let what = what_label(shell);
+ let what = crate::output::shell_integration::shell_extension_label(shell);
let detection = detection_results
.iter()
@@ -908,7 +895,7 @@ fn render_would_add_or_create(
) -> anyhow::Result<bool> {
let shell = result.shell;
let path = format_path_for_display(&result.path);
- let what = what_label(shell);
+ let what = crate::output::shell_integration::shell_extension_label(shell);
// Fish: prefer migration hint when the legacy conf.d location has
// working integration — silencing the "Not configured" row.
@@ -1059,8 +1046,8 @@ fn render_shell_status(out: &mut String) -> anyhow::Result<()> {
let mut has_any_unmatched = false;
// Show configured and not-configured shells (matching `config shell install` format exactly)
- // Bash/Zsh: inline completions, show "shell extension & completions"
- // Fish: separate completion file, show "shell extension" for functions/ and "completions" for completions/
+ // Fish ships completions as a separate file: "shell extension" for functions/ and "completions" for completions/
+ // Every other supported shell wires completions inline with the extension, so they show "shell extension & completions"
for result in &scan_result.configured {
match result.action {
ConfigAction::AlreadyExists => {
diff --git a/src/commands/configure_shell.rs b/src/commands/configure_shell.rs
index 4437c3a47..21595babc 100644
--- a/src/commands/configure_shell.rs
+++ b/src/commands/configure_shell.rs
@@ -12,6 +12,7 @@ use worktrunk::styling::{
};
use crate::output::prompt::{PromptResponse, prompt_yes_no_preview};
+use crate::output::shell_integration::shell_extension_label;
pub struct ConfigureResult {
pub shell: Shell,
@@ -671,12 +672,7 @@ pub fn show_install_preview(
let shell = result.shell;
let path = format_path_for_display(&result.path);
- // Bash/Zsh: inline completions; Fish/PowerShell: separate or no completions
- let what = if matches!(shell, Shell::Bash | Shell::Zsh) {
- "shell extension & completions"
- } else {
- "shell extension"
- };
+ let what = shell_extension_label(shell);
eprintln!(
"{} {} {what} for {bold}{shell}{bold:#} @ {bold}{path}{bold:#}",
@@ -750,15 +746,7 @@ pub fn show_uninstall_preview(
result.action.description(),
);
} else {
- // Only Bash/Zsh ship inline completions alongside the extension;
- // Fish/Nushell/PowerShell either use a separate completion file
- // (Fish) or no completions at all. Keep this in sync with
- // `show_install_preview` and `prompt_for_uninstall_confirmation`.
- let what = if matches!(shell, Shell::Bash | Shell::Zsh) {
- "shell extension & completions"
- } else {
- "shell extension"
- };
+ let what = shell_extension_label(shell);
eprintln!(
"{} {} {what} for {bold}{shell}{bold:#} @ {bold}{path}{bold:#}",
@@ -1207,12 +1195,7 @@ fn prompt_for_uninstall_confirmation(
let bold = Style::new().bold();
let shell = result.shell;
let path = format_path_for_display(&result.path);
- // Bash/Zsh: inline completions; Fish/PowerShell: separate or no completions
- let what = if matches!(shell, Shell::Bash | Shell::Zsh) {
- "shell extension & completions"
- } else {
- "shell extension"
- };
+ let what = shell_extension_label(shell);
eprintln!(
"{} {} {what} for {bold}{shell}{bold:#} @ {bold}{path}{bold:#}",
diff --git a/src/output/shell_integration.rs b/src/output/shell_integration.rs
index 81b47c2f4..35dca2cad 100644
--- a/src/output/shell_integration.rs
+++ b/src/output/shell_integration.rs
@@ -224,12 +224,18 @@ pub fn print_skipped_shells(skipped: &[(worktrunk::shell::Shell, std::path::Path
}
}
-fn shell_extension_label(shell: Shell) -> &'static str {
- // For bash/zsh, completions are inline in the init script.
- if matches!(shell, Shell::Bash | Shell::Zsh) {
- "shell extension & completions"
- } else {
+/// Per-shell label distinguishing Fish (its completions live in a
+/// separate file under `~/.config/fish/completions/` rendered on its own
+/// line) from every other supported shell, which ships completions
+/// inline with the extension — bash/zsh via the init script, nushell via
+/// the `@complete` attribute on the wrapper, and powershell via
+/// `Register-ArgumentCompleter`. Single source of truth so the label
+/// can't drift across the install/uninstall/preview/config-show paths.
+pub(crate) fn shell_extension_label(shell: Shell) -> &'static str {
+ if matches!(shell, Shell::Fish) {
"shell extension"
+ } else {
+ "shell extension & completions"
}
}
diff --git a/tests/integration_tests/configure_shell.rs b/tests/integration_tests/configure_shell.rs
index d68cfca54..6d0cf1741 100644
--- a/tests/integration_tests/configure_shell.rs
+++ b/tests/integration_tests/configure_shell.rs
@@ -882,7 +882,7 @@ fn test_uninstall_shell(repo: TestRepo, temp_home: TempDir) {
✓ Removed shell extension & completions for zsh @ ~/.zshrc
↳ No bash shell extension & completions in ~/.bashrc
↳ No fish shell extension in ~/.config/fish/functions/wt.fish
- ↳ No nu shell extension in ~/.config/nushell/vendor/autoload/wt.nu
+ ↳ No nu shell extension & completions in ~/.config/nushell/vendor/autoload/wt.nu
↳ No fish completions in ~/.config/fish/completions/wt.fish
✓ Removed integration from 1 shell
@@ -939,7 +939,7 @@ fn test_uninstall_shell_multiple(repo: TestRepo, temp_home: TempDir) {
✓ Removed shell extension & completions for bash @ ~/.bashrc
✓ Removed shell extension & completions for zsh @ ~/.zshrc
↳ No fish shell extension in ~/.config/fish/functions/wt.fish
- ↳ No nu shell extension in ~/.config/nushell/vendor/autoload/wt.nu
+ ↳ No nu shell extension & completions in ~/.config/nushell/vendor/autoload/wt.nu
↳ No fish completions in ~/.config/fish/completions/wt.fish
✓ Removed integration from 2 shells
@@ -1655,12 +1655,12 @@ fn test_uninstall_shell_dry_run_multiple(repo: TestRepo, temp_home: TempDir) {
);
}
-/// Regression: `--dry-run uninstall nu` (and pwsh by extension) previously
-/// printed `Would remove shell extension & completions for nu`, but Nushell
-/// has no inline completions — only Bash/Zsh do. The other two render paths
-/// (`show_install_preview`, `prompt_for_uninstall_confirmation`) already
-/// keyed off `Shell::Bash | Shell::Zsh`; the dry-run uninstall path was the
-/// odd one out, treating Fish as the only no-completions shell.
+/// Regression: nushell's wrapper wires completions inline via the
+/// `@complete` attribute on the wrapper's rest parameter, so its
+/// extension does ship completions — only Fish keeps completions in a
+/// separate file. The `--dry-run uninstall` path (and the other four
+/// label sites) must reflect that and label nushell as
+/// `shell extension & completions`.
#[rstest]
fn test_uninstall_shell_dry_run_nushell(repo: TestRepo, temp_home: TempDir) {
// Install nushell integration first so dry-run uninstall finds something.
@@ -1694,13 +1694,8 @@ fn test_uninstall_shell_dry_run_nushell(repo: TestRepo, temp_home: TempDir) {
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
- stderr.contains("shell extension for") && stderr.contains("nu"),
- "Dry-run output should label nushell as 'shell extension' (no '& completions'):\n{stderr}"
- );
- assert!(
- !stderr.contains("shell extension & completions for [1mnu")
- && !stderr.contains("shell extension & completions for nu"),
- "Nushell must NOT be labeled 'shell extension & completions':\n{stderr}"
+ stderr.contains("shell extension & completions for") && stderr.contains("nu"),
+ "Dry-run output should label nushell as 'shell extension & completions':\n{stderr}"
);
}
@@ -1806,6 +1801,51 @@ mod pty_tests {
"File should not be modified when user declines"
);
}
+
+ /// Declining the interactive `wt config shell uninstall` prompt
+ /// exercises `prompt_for_uninstall_confirmation` — the one render
+ /// path that neither `--yes` nor `--dry-run` reaches. Verifies the
+ /// preview labels zsh as `shell extension & completions` (matching
+ /// the dedicated `shell_extension_label` helper) and that declining
+ /// leaves the rcfile untouched.
+ #[rstest]
+ fn test_uninstall_preview_declined(repo: TestRepo, temp_home: TempDir) {
+ let zshrc_path = temp_home.path().join(".zshrc");
+ let initial = "# Existing config\nif command -v wt >/dev/null 2>&1; then eval \"$(command wt config shell init zsh)\"; fi\n";
+ fs::write(&zshrc_path, initial).unwrap();
+
+ let mut cmd = CommandBuilder::new(wt_bin());
+ cmd.arg("-C");
+ cmd.arg(repo.root_path());
+ cmd.arg("config");
+ cmd.arg("shell");
+ cmd.arg("uninstall");
+ cmd.cwd(repo.root_path());
+
+ configure_pty_command(&mut cmd);
+ cmd.env("HOME", temp_home.path());
+ cmd.env("XDG_CONFIG_HOME", temp_home.path().join(".config"));
+ cmd.env("WORKTRUNK_TEST_BASH_INSTALLED", "0");
+ cmd.env("WORKTRUNK_TEST_ZSH_INSTALLED", "0");
+ cmd.env("WORKTRUNK_TEST_FISH_INSTALLED", "0");
+ cmd.env("WORKTRUNK_TEST_POWERSHELL_INSTALLED", "0");
+ cmd.env("WORKTRUNK_TEST_NUSHELL_ENV", "0");
+ cmd.env("SHELL", "/bin/zsh");
+
+ let (output, exit_code) = exec_cmd_in_pty_prompted(cmd, &["n\n"], "[y/N");
+
+ // Decline → exit code 1, file unchanged.
+ assert_eq!(exit_code, 1);
+ assert!(
+ output.contains("shell extension & completions") && output.contains("zsh"),
+ "Preview should label zsh as 'shell extension & completions':\n{output}"
+ );
+ let content = fs::read_to_string(&zshrc_path).unwrap();
+ assert_eq!(
+ content, initial,
+ "Declining uninstall should leave the rcfile untouched",
+ );
+ }
}
/// Test installing nushell shell integration
@@ -1837,7 +1877,7 @@ fn test_configure_shell_nushell(repo: TestRepo, temp_home: TempDir) {
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
- stderr.contains("Created shell extension for") && stderr.contains("nu"),
+ stderr.contains("Created shell extension & completions for") && stderr.contains("nu"),
"Output should show nushell was created:\n{}",
stderr
);
@@ -1917,7 +1957,7 @@ fn test_uninstall_shell_nushell(repo: TestRepo, temp_home: TempDir) {
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
- stderr.contains("Removed shell extension for") && stderr.contains("nu"),
+ stderr.contains("Removed shell extension & completions for") && stderr.contains("nu"),
"Output should show nushell was removed:\n{}",
stderr
);
@@ -2042,7 +2082,8 @@ fn test_powershell_env_detection(repo: TestRepo, temp_home: TempDir) {
let stderr = String::from_utf8_lossy(&output.stderr);
// Check that PowerShell was configured (not skipped)
assert!(
- stderr.contains("Created shell extension for") && stderr.contains("powershell"),
+ stderr.contains("Created shell extension & completions for")
+ && stderr.contains("powershell"),
"Output should show PowerShell was created:\n{}",
stderr
);
@@ -2095,7 +2136,7 @@ fn test_nushell_auto_detection_creates_vendor_autoload(repo: TestRepo, temp_home
let stderr = String::from_utf8_lossy(&output.stderr);
// Nushell should be configured, not skipped
assert!(
- stderr.contains("Created shell extension for") && stderr.contains("nu"),
+ stderr.contains("Created shell extension & completions for") && stderr.contains("nu"),
"Nushell should be auto-configured when detected:\n{}",
stderr
);