Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Move zsh compinit advisory to after success message
Maximilian Roos14ac1bd9d5b6
diff --git a/src/commands/configure_shell.rs b/src/commands/configure_shell.rsindex b041d3da7..003864045 100644--- a/src/commands/configure_shell.rs+++ b/src/commands/configure_shell.rs@@ -41,6 +41,8 @@ pub struct ScanResult {pub configured: Vec<ConfigureResult>,pub completion_results: Vec<CompletionResult>,pub skipped: Vec<(Shell, PathBuf)>, // Shell + first path that was checked+ /// Zsh was configured but compinit is missing (completions won't work without it)+ pub zsh_needs_compinit: bool,}pub struct CompletionResult {@@ -119,6 +121,7 @@ pub fn handle_configure_shell(configured: preview.configured,completion_results: completion_preview,skipped: preview.skipped,+ zsh_needs_compinit: false,});}@@ -137,6 +140,7 @@ pub fn handle_configure_shell(configured: preview.configured,completion_results: completion_preview,skipped: preview.skipped,+ zsh_needs_compinit: false,});}@@ -153,13 +157,13 @@ pub fn handle_configure_shell(// Zsh completions require compinit to be enabled. Unlike bash/fish, zsh doesn't// enable its completion system by default - users must explicitly call compinit.- // We detect this and show an advisory hint to help users get completions working.+ // We detect this and return a flag so the caller can show an appropriate advisory.//- // We only show this advisory during `install`, not `init`, because:+ // We only check this during `install`, not `init`, because:// - `init` outputs a script that gets eval'd - advisory would pollute that// - `install` is the user-facing command where hints are appropriate//- // We show the advisory when:+ // We check when:// - User explicitly runs `install zsh` (they clearly want zsh integration)// - User runs `install` (all shells) AND their $SHELL is zsh (they use zsh daily)//@@ -175,18 +179,10 @@ pub fn handle_configure_shell(&& (shell_filter == Some(Shell::Zsh)|| (shell_filter.is_none() && shell::is_current_shell_zsh()));- if should_check_compinit {- // Probe user's zsh to check if compinit is enabled.- // Only show advisory if we positively detect it's missing (Some(false)).- // If detection fails (None), stay silent - we can't be sure.- if shell::detect_zsh_compinit() == Some(false) {- let _ = crate::output::print(warning_message(- "Completions won't work; add to ~/.zshrc before the wt line:",- ));- let _ =- crate::output::gutter(format_bash_with_gutter("autoload -Uz compinit && compinit"));- }- }+ // Probe user's zsh to check if compinit is enabled.+ // Only flag if we positively detect it's missing (Some(false)).+ // If detection fails (None), stay silent - we can't be sure.+ let zsh_needs_compinit = should_check_compinit && shell::detect_zsh_compinit() == Some(false);// On Windows without Git Bash, show advisory about PowerShell limitationslet powershell_was_configured = result@@ -208,6 +204,7 @@ pub fn handle_configure_shell(configured: result.configured,completion_results,skipped: result.skipped,+ zsh_needs_compinit,})}@@ -289,6 +286,7 @@ pub fn scan_shell_configs(configured: results,completion_results: Vec::new(), // Completions handled separately in handle_configure_shellskipped,+ zsh_needs_compinit: false, // Caller handles compinit detection})}diff --git a/src/main.rs b/src/main.rsindex bfc45f562..355a79643 100644--- a/src/main.rs+++ b/src/main.rs@@ -830,6 +830,18 @@ fn main() {crate::output::print(success_message("All shells already configured"))?;}+ // Zsh compinit advisory: shown after success, before restart hint+ if scan_result.zsh_needs_compinit {+ crate::output::print(warning_message(+ "Completions require compinit; add to ~/.zshrc before the wt line:",+ ))?;+ crate::output::gutter(+ worktrunk::styling::format_bash_with_gutter(+ "autoload -Uz compinit && compinit",+ ),+ )?;+ }+// Restart hint: only shown if the current shell's extension changed// Fish completions are lazily loaded from ~/.config/fish/completions/// so no restart needed. Bash/Zsh completions are inline in the init script.diff --git a/tests/integration_tests/configure_shell.rs b/tests/integration_tests/configure_shell.rsindex 64b11c3d6..b924d455b 100644--- a/tests/integration_tests/configure_shell.rs+++ b/tests/integration_tests/configure_shell.rs@@ -33,13 +33,13 @@ fn test_configure_shell_with_yes(repo: TestRepo, temp_home: TempDir) {----- stdout ---------- stderr ------ [33m▲[39m [33mCompletions won't work; add to ~/.zshrc before the wt line:[39m- [107m [0m [2m[0m[2m[34mautoload[0m[2m [0m[2m[36m-Uz[0m[2m compinit [0m[2m[36m&&[0m[2m [0m[2m[34mcompinit[0m[2m[0m[32m✓[39m [32mAdded shell extension & completions for [1mzsh[22m @ [1m~/.zshrc[22m[39m[2m↳[22m [2mSkipped [90mbash[39m; ~/.bashrc not found[22m[2m↳[22m [2mSkipped [90mfish[39m; ~/.config/fish/conf.d not found[22m[32m✓[39m [32mConfigured 1 shell[39m+ [33m▲[39m [33mCompletions require compinit; add to ~/.zshrc before the wt line:[39m+ [107m [0m [2m[0m[2m[34mautoload[0m[2m [0m[2m[36m-Uz[0m[2m compinit [0m[2m[36m&&[0m[2m [0m[2m[34mcompinit[0m[2m[0m[2m↳[22m [2mRestart shell or run: source ~/.zshrc[22m");});@@ -77,11 +77,11 @@ fn test_configure_shell_specific_shell(repo: TestRepo, temp_home: TempDir) {----- stdout ---------- stderr ------ [33m▲[39m [33mCompletions won't work; add to ~/.zshrc before the wt line:[39m- [107m [0m [2m[0m[2m[34mautoload[0m[2m [0m[2m[36m-Uz[0m[2m compinit [0m[2m[36m&&[0m[2m [0m[2m[34mcompinit[0m[2m[0m[32m✓[39m [32mAdded shell extension & completions for [1mzsh[22m @ [1m~/.zshrc[22m[39m[32m✓[39m [32mConfigured 1 shell[39m+ [33m▲[39m [33mCompletions require compinit; add to ~/.zshrc before the wt line:[39m+ [107m [0m [2m[0m[2m[34mautoload[0m[2m [0m[2m[36m-Uz[0m[2m compinit [0m[2m[36m&&[0m[2m [0m[2m[34mcompinit[0m[2m[0m[2m↳[22m [2mRestart shell or run: source ~/.zshrc[22m");});@@ -324,13 +324,13 @@ fn test_configure_shell_multiple_configs(repo: TestRepo, temp_home: TempDir) {----- stdout ---------- stderr ------ [33m▲[39m [33mCompletions won't work; add to ~/.zshrc before the wt line:[39m- [107m [0m [2m[0m[2m[34mautoload[0m[2m [0m[2m[36m-Uz[0m[2m compinit [0m[2m[36m&&[0m[2m [0m[2m[34mcompinit[0m[2m[0m[32m✓[39m [32mAdded shell extension & completions for [1mbash[22m @ [1m~/.bashrc[22m[39m[32m✓[39m [32mAdded shell extension & completions for [1mzsh[22m @ [1m~/.zshrc[22m[39m[2m↳[22m [2mSkipped [90mfish[39m; ~/.config/fish/conf.d not found[22m[32m✓[39m [32mConfigured 2 shells[39m+ [33m▲[39m [33mCompletions require compinit; add to ~/.zshrc before the wt line:[39m+ [107m [0m [2m[0m[2m[34mautoload[0m[2m [0m[2m[36m-Uz[0m[2m compinit [0m[2m[36m&&[0m[2m [0m[2m[34mcompinit[0m[2m[0m[2m↳[22m [2mRestart shell or run: source ~/.zshrc[22m");});@@ -384,13 +384,13 @@ fn test_configure_shell_mixed_states(repo: TestRepo, temp_home: TempDir) {----- stdout ---------- stderr ------ [33m▲[39m [33mCompletions won't work; add to ~/.zshrc before the wt line:[39m- [107m [0m [2m[0m[2m[34mautoload[0m[2m [0m[2m[36m-Uz[0m[2m compinit [0m[2m[36m&&[0m[2m [0m[2m[34mcompinit[0m[2m[0m[2m○[22m Already configured shell extension & completions for [1mbash[22m @ [1m~/.bashrc[22m[32m✓[39m [32mAdded shell extension & completions for [1mzsh[22m @ [1m~/.zshrc[22m[39m[2m↳[22m [2mSkipped [90mfish[39m; ~/.config/fish/conf.d not found[22m[32m✓[39m [32mConfigured 1 shell[39m+ [33m▲[39m [33mCompletions require compinit; add to ~/.zshrc before the wt line:[39m+ [107m [0m [2m[0m[2m[34mautoload[0m[2m [0m[2m[36m-Uz[0m[2m compinit [0m[2m[36m&&[0m[2m [0m[2m[34mcompinit[0m[2m[0m[2m↳[22m [2mRestart shell or run: source ~/.zshrc[22m");});diff --git a/tests/integration_tests/snapshots/integration__integration_tests__configure_shell__pty_tests__install_preview_with_gutter.snap b/tests/integration_tests/snapshots/integration__integration_tests__configure_shell__pty_tests__install_preview_with_gutter.snapindex 3e9d4a23b..06dd4628c 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__configure_shell__pty_tests__install_preview_with_gutter.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__configure_shell__pty_tests__install_preview_with_gutter.snap@@ -8,11 +8,11 @@ yif command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)"; fi❯ Proceed? [y/N]-▲ Completions won't work; add to ~/.zshrc before the wt line:- autoload -Uz compinit && compinit✓ Added shell extension & completions for zsh @ ~/.zshrc↳ Skipped bash; ~/.bashrc not found↳ Skipped fish; ~/.config/fish/conf.d not found✓ Configured 1 shell+▲ Completions require compinit; add to ~/.zshrc before the wt line:+ autoload -Uz compinit && compinit↳ Restart shell or run: source ~/.zshrc