Skip to content

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

refactor: Improve configure shell command output

Maximilian Roosa49708ba1f6a
diff --git a/src/commands/configure_shell.rs b/src/commands/configure_shell.rs
index fa99ceb82..478dafb34 100644
--- a/src/commands/configure_shell.rs
+++ b/src/commands/configure_shell.rs
@@ -14,6 +14,11 @@ pub struct ConfigureResult {
pub config_line: String,
}
+pub struct ScanResult {
+ pub configured: Vec<ConfigureResult>,
+ pub skipped: Vec<(Shell, PathBuf)>, // Shell + first path that was checked
+}
+
#[derive(Debug, PartialEq)]
pub enum ConfigAction {
Added,
@@ -48,27 +53,28 @@ pub fn handle_configure_shell(
shell_filter: Option<Shell>,
skip_confirmation: bool,
command_name: String,
-) -> Result<Vec<ConfigureResult>, String> {
+) -> Result<ScanResult, String> {
// First, do a dry-run to see what would be changed
- let preview_results = scan_shell_configs(shell_filter, true, &command_name)?;
+ let preview = scan_shell_configs(shell_filter, true, &command_name)?;
// If nothing to do, return early
- if preview_results.is_empty() {
- return Ok(vec![]);
+ if preview.configured.is_empty() {
+ return Ok(preview);
}
// Check if any changes are needed (not all are AlreadyExists)
- let needs_changes = preview_results
+ let needs_changes = preview
+ .configured
.iter()
.any(|r| !matches!(r.action, ConfigAction::AlreadyExists));
// If nothing needs to be changed, just return the preview results
if !needs_changes {
- return Ok(preview_results);
+ return Ok(preview);
}
// Show what will be done and ask for confirmation (unless --force flag is used)
- if !skip_confirmation && !prompt_for_confirmation(&preview_results)? {
+ if !skip_confirmation && !prompt_for_confirmation(&preview.configured)? {
return Err("Cancelled by user".to_string());
}
@@ -80,7 +86,7 @@ fn scan_shell_configs(
shell_filter: Option<Shell>,
dry_run: bool,
command_name: &str,
-) -> Result<Vec<ConfigureResult>, String> {
+) -> Result<ScanResult, String> {
let shells = if let Some(shell) = shell_filter {
vec![shell]
} else {
@@ -94,7 +100,7 @@ fn scan_shell_configs(
};
let mut results = Vec::new();
- let mut checked_paths = Vec::new();
+ let mut skipped = Vec::new();
for shell in shells {
let paths = shell.config_paths(command_name);
@@ -115,9 +121,6 @@ fn scan_shell_configs(
target_path.is_some()
};
- // Track all checked paths for better error messages
- checked_paths.extend(paths.iter().map(|p| (shell, p.clone())));
-
// Only configure if explicitly targeting this shell OR if config file/location exists
let should_configure = shell_filter.is_some() || has_config_location;
@@ -140,24 +143,32 @@ fn scan_shell_configs(
}
}
}
+ } else if shell_filter.is_none() {
+ // Track skipped shells (only when not explicitly filtering)
+ // For Fish, we check for conf.d directory; for others, the config file
+ let skipped_path = if matches!(shell, Shell::Fish) {
+ paths
+ .first()
+ .and_then(|p| p.parent())
+ .map(|p| p.to_path_buf())
+ } else {
+ paths.first().cloned()
+ };
+ if let Some(path) = skipped_path {
+ skipped.push((shell, path));
+ }
}
}
- if results.is_empty() && shell_filter.is_none() {
- // Provide helpful error message with checked locations
- let example_paths: Vec<String> = checked_paths
- .iter()
- .take(3)
- .map(|(_, p)| p.display().to_string())
- .collect();
-
- return Err(format!(
- "No shell config files found in $HOME. Checked: {}, and more. Create a config file or use --shell to specify a shell.",
- example_paths.join(", ")
- ));
+ if results.is_empty() && shell_filter.is_none() && skipped.is_empty() {
+ // No shells checked at all (shouldn't happen normally)
+ return Err("No shell config files found".to_string());
}
- Ok(results)
+ Ok(ScanResult {
+ configured: results,
+ skipped,
+ })
}
fn configure_shell_file(
diff --git a/src/main.rs b/src/main.rs
index 46e28dede..dee023a3f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -196,28 +196,18 @@ fn main() {
// Auto-write to shell config files
handle_configure_shell(shell, force, command_name)
.map_err(|e| anyhow::anyhow!("{}", e))
- .map(|results| {
+ .and_then(|scan_result| {
use anstyle::{AnsiColor, Color};
+ use worktrunk::styling::{HINT, HINT_EMOJI, format_bash_with_gutter};
- // Count actual changes (not AlreadyExists)
- let changes_count = results
+ let changes_count = scan_result
+ .configured
.iter()
.filter(|r| !matches!(r.action, ConfigAction::AlreadyExists))
.count();
- if changes_count == 0 {
- // All shells already configured
- let green =
- Style::new().fg_color(Some(Color::Ansi(AnsiColor::Green)));
- println!(
- "{SUCCESS_EMOJI} {green}All shells already configured{green:#}"
- );
- return;
- }
-
- // Show what was done (instant operations, no progress needed)
- for result in &results {
- use worktrunk::styling::format_bash_with_gutter;
+ // Show configured shells
+ for result in &scan_result.configured {
let bold = Style::new().bold();
let shell = result.shell;
let path = format_path_for_display(&result.path);
@@ -227,24 +217,42 @@ fn main() {
result.action.emoji(),
result.action.description(),
);
- // Show config line with gutter
- print!("{}", format_bash_with_gutter(&result.config_line, ""));
+ // Show config line only for new additions
+ if changes_count > 0 {
+ print!("{}", format_bash_with_gutter(&result.config_line, ""));
+ }
+ }
+
+ // Show skipped shells
+ let dimmed = Style::new().dimmed();
+ for (shell, path) in &scan_result.skipped {
+ let path = format_path_for_display(path);
+ println!("{HINT_EMOJI} {dimmed}{shell} {path} (not found){dimmed:#}");
+ }
+
+ // Exit with error if no shells configured
+ if scan_result.configured.is_empty() {
+ return Err(anyhow::anyhow!("No shell config files found"));
}
- // Success summary
- println!();
+ // Summary
let green = Style::new().fg_color(Some(Color::Ansi(AnsiColor::Green)));
- let plural = if changes_count == 1 { "" } else { "s" };
- println!(
- "{SUCCESS_EMOJI} {green}Configured {changes_count} shell{plural}{green:#}"
- );
-
- // Show hint about restarting shell
- println!();
- use worktrunk::styling::{HINT, HINT_EMOJI};
- println!(
- "{HINT_EMOJI} {HINT}Restart your shell or run: source <config-file>{HINT:#}"
- );
+ if changes_count > 0 {
+ println!();
+ let plural = if changes_count == 1 { "" } else { "s" };
+ println!(
+ "{SUCCESS_EMOJI} {green}Configured {changes_count} shell{plural}{green:#}"
+ );
+ println!();
+ println!(
+ "{HINT_EMOJI} {HINT}Restart your shell or run: source <config-file>{HINT:#}"
+ );
+ } else {
+ println!(
+ "{SUCCESS_EMOJI} {green}All shells already configured{green:#}"
+ );
+ }
+ Ok(())
})
}
},
diff --git a/tests/integration_tests/configure_shell.rs b/tests/integration_tests/configure_shell.rs
index 296810127..f2eccc9f5 100644
--- a/tests/integration_tests/configure_shell.rs
+++ b/tests/integration_tests/configure_shell.rs
@@ -30,6 +30,8 @@ fn test_configure_shell_with_yes() {
----- stdout -----
βœ… Added zsh ~/.zshrc
  if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)"; fi
+ πŸ’‘ bash ~/.bash_profile (not found)
+ πŸ’‘ fish ~/.config/fish/conf.d (not found)
βœ… Configured 1 shell
@@ -116,6 +118,7 @@ fn test_configure_shell_already_exists() {
success: true
exit_code: 0
----- stdout -----
+ βšͺ Already configured zsh ~/.zshrc
βœ… All shells already configured
----- stderr -----
@@ -200,7 +203,10 @@ fn test_configure_shell_no_files() {
success: false
exit_code: 1
----- stdout -----
- ❌ No shell config files found in $HOME. Checked: [TEMP_HOME]/.bash_profile, [TEMP_HOME]/.zshrc, and more. Create a config file or use --shell to specify a shell.
+ πŸ’‘ bash ~/.bash_profile (not found)
+ πŸ’‘ zsh ~/.zshrc (not found)
+ πŸ’‘ fish ~/.config/fish/conf.d (not found)
+ ❌ No shell config files found
----- stderr -----
");
@@ -238,6 +244,7 @@ fn test_configure_shell_multiple_configs() {
  if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init bash)"; fi
βœ… Added zsh ~/.zshrc
  if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)"; fi
+ πŸ’‘ fish ~/.config/fish/conf.d (not found)
βœ… Configured 2 shells
@@ -298,6 +305,7 @@ fn test_configure_shell_mixed_states() {
  if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init bash)"; fi
βœ… Added zsh ~/.zshrc
  if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)"; fi
+ πŸ’‘ fish ~/.config/fish/conf.d (not found)
βœ… Configured 1 shell