Skip to content

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

fix: move fish shell integration to functions/ for Homebrew compatibility (#580)

Maximilian Roos62dfad15622d
diff --git a/.typos.toml b/.typos.toml
index b53a327c9..783d8808e 100644
--- a/.typos.toml
+++ b/.typos.toml
@@ -1,5 +1,5 @@
[files]
-extend-exclude = ["docs/demos/vhs-keystrokes/"]
+extend-exclude = ["docs/demos/vhs-keystrokes/", "*.snap"]
[default.extend-words]
# Git commit hashes that typos flags as potential typos
diff --git a/src/commands/config.rs b/src/commands/config.rs
index 8d80f1071..8b808322b 100644
--- a/src/commands/config.rs
+++ b/src/commands/config.rs
@@ -505,12 +505,23 @@ fn render_shell_status(out: &mut String) -> anyhow::Result<()> {
// Get detection details to show matched lines inline
let detection_results = scan_for_detection_details(&cmd).unwrap_or_default();
+ // Check for legacy fish conf.d path (deprecated location from before #566)
+ // We need this early to handle the case where fish shows "Not configured" at the
+ // new location but has valid integration at the legacy location.
+ let legacy_fish_conf_d = Shell::legacy_fish_conf_d_path(&cmd).ok();
+ let legacy_fish_has_integration = legacy_fish_conf_d.as_ref().is_some_and(|legacy_path| {
+ detection_results
+ .iter()
+ .any(|d| d.path == *legacy_path && !d.matched_lines.is_empty())
+ });
+
let mut any_not_configured = false;
+ let mut not_configured_shells: Vec<Shell> = Vec::new();
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 conf.d and "completions" for completions/
+ // Fish: separate completion file, show "shell extension" for functions/ and "completions" for completions/
for result in &scan_result.configured {
let shell = result.shell;
let path = format_path_for_display(&result.path);
@@ -597,30 +608,93 @@ fn render_shell_status(out: &mut String) -> anyhow::Result<()> {
)?;
} else {
any_not_configured = true;
+ if !not_configured_shells.contains(&shell) {
+ not_configured_shells.push(shell);
+ }
writeln!(
out,
"{}",
- hint_message(format!(
- "Not configured completions for {shell} @ {completion_display}"
- ))
+ hint_message(format!("Not configured completions for {shell}"))
)?;
}
}
}
ConfigAction::WouldAdd | ConfigAction::WouldCreate => {
- any_not_configured = true;
- writeln!(
- out,
- "{}",
- hint_message(format!("Not configured {what} for {shell} @ {path}"))
- )?;
+ // For fish, check if we have valid integration at the legacy conf.d location
+ if matches!(shell, Shell::Fish) && legacy_fish_has_integration {
+ // Show migration hint instead of "Not configured"
+ let legacy_path = legacy_fish_conf_d
+ .as_ref()
+ .map(|p| format_path_for_display(p))
+ .unwrap_or_default();
+ writeln!(
+ out,
+ "{}",
+ info_message(cformat!(
+ "Fish integration found in deprecated location @ <bold>{legacy_path}</>"
+ ))
+ )?;
+ // Get canonical path for the migration hint
+ let canonical_path = Shell::Fish
+ .config_paths(&cmd)
+ .ok()
+ .and_then(|p| p.into_iter().next())
+ .map(|p| format_path_for_display(&p))
+ .unwrap_or_else(|| "~/.config/fish/functions/".to_string());
+ writeln!(
+ out,
+ "{}",
+ hint_message(cformat!(
+ "To migrate to <bright-black>{canonical_path}</>, run <bright-black>{cmd} config shell install fish</>"
+ ))
+ )?;
+ } else {
+ any_not_configured = true;
+ if !not_configured_shells.contains(&shell) {
+ not_configured_shells.push(shell);
+ }
+ writeln!(
+ out,
+ "{}",
+ hint_message(format!("Not configured {what} for {shell}"))
+ )?;
+ }
}
_ => {} // Added/Created won't appear in dry_run mode
}
}
// Show skipped (not installed) shells
+ // For fish with legacy integration, show migration hint instead of "skipped"
for (shell, path) in &scan_result.skipped {
+ if matches!(shell, Shell::Fish) && legacy_fish_has_integration {
+ // Show migration hint for legacy fish location
+ let legacy_path = legacy_fish_conf_d
+ .as_ref()
+ .map(|p| format_path_for_display(p))
+ .unwrap_or_default();
+ let canonical_path = Shell::Fish
+ .config_paths(&cmd)
+ .ok()
+ .and_then(|p| p.into_iter().next())
+ .map(|p| format_path_for_display(&p))
+ .unwrap_or_else(|| "~/.config/fish/functions/".to_string());
+ writeln!(
+ out,
+ "{}",
+ info_message(cformat!(
+ "Fish integration found in deprecated location @ <bold>{legacy_path}</>"
+ ))
+ )?;
+ writeln!(
+ out,
+ "{}",
+ hint_message(cformat!(
+ "To migrate to <bright-black>{canonical_path}</>, run <bright-black>{cmd} config shell install fish</>"
+ ))
+ )?;
+ continue;
+ }
let path = format_path_for_display(path);
writeln!(
out,
@@ -629,23 +703,28 @@ fn render_shell_status(out: &mut String) -> anyhow::Result<()> {
)?;
}
- // Summary hint
- if any_not_configured {
+ // Summary hint - be specific about which shells need configuration
+ if any_not_configured && !not_configured_shells.is_empty() {
writeln!(out)?;
+ // CLI accepts one shell at a time, so suggest the base command
+ // which auto-detects and configures all available shells
writeln!(
out,
"{}",
hint_message(cformat!(
- "To enable shell integration, run <bright-black>wt config shell install</>"
+ "To configure, run <bright-black>{cmd} config shell install</>"
))
)?;
}
// Show potential false negatives (lines containing cmd but not detected)
+ // Skip files that have valid integration detected (matched_lines) - those are fine,
+ // and the other lines containing cmd are just part of the integration script.
for detection in &detection_results {
- if !detection.unmatched_candidates.is_empty() {
+ if !detection.unmatched_candidates.is_empty() && detection.matched_lines.is_empty() {
has_any_unmatched = true;
let path = format_path_for_display(&detection.path);
+
// Build file:line location (clickable in terminals)
let line_nums: Vec<_> = detection
.unmatched_candidates
@@ -736,12 +815,21 @@ fn render_shell_status(out: &mut String) -> anyhow::Result<()> {
urlencoding::encode(&body)
);
- writeln!(out)?;
+ // Quote a short version of the unmatched content in the hint
+ let quoted = if unmatched_summary.len() == 1 {
+ format!("`{}`", unmatched_summary[0])
+ } else {
+ format!(
+ "`{}` (and {} more)",
+ unmatched_summary[0],
+ unmatched_summary.len() - 1
+ )
+ };
writeln!(
out,
"{}",
hint_message(format!(
- "If this is shell integration, report a false negative: {issue_url}"
+ "If {quoted} is shell integration, report a false negative: {issue_url}"
))
)?;
}
diff --git a/src/commands/configure_shell.rs b/src/commands/configure_shell.rs
index 1dae2e96c..25aa8ece1 100644
--- a/src/commands/configure_shell.rs
+++ b/src/commands/configure_shell.rs
@@ -21,6 +21,8 @@ pub struct UninstallResult {
pub shell: Shell,
pub path: PathBuf,
pub action: UninstallAction,
+ /// Path that replaces this one (for deprecated location cleanup)
+ pub superseded_by: Option<PathBuf>,
}
pub struct UninstallScanResult {
@@ -44,6 +46,8 @@ pub struct ScanResult {
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,
+ /// Legacy files that were cleaned up (e.g., fish conf.d/wt.fish -> functions/wt.fish migration)
+ pub legacy_cleanups: Vec<PathBuf>,
}
pub struct CompletionResult {
@@ -104,6 +108,68 @@ impl ConfigAction {
}
}
+/// Check if file content appears to be worktrunk-managed (contains our markers)
+fn is_worktrunk_managed_content(content: &str, cmd: &str) -> bool {
+ content.contains(&format!("{cmd} config shell init"))
+}
+
+/// Clean up legacy fish conf.d file after installing to functions/
+///
+/// Previously, fish shell integration was installed to `~/.config/fish/conf.d/{cmd}.fish`.
+/// This caused issues with Homebrew PATH setup (see issue #566). We now install to
+/// `functions/{cmd}.fish` instead. This function removes the legacy file if it exists.
+///
+/// Returns the paths of files that were cleaned up.
+fn cleanup_legacy_fish_conf_d(configured: &[ConfigureResult], cmd: &str) -> Vec<PathBuf> {
+ use worktrunk::path::format_path_for_display;
+ use worktrunk::styling::warning_message;
+
+ let mut cleaned = Vec::new();
+
+ // Clean up if fish was part of the install (regardless of whether it already existed)
+ // This handles the case where user manually created functions/wt.fish but still has
+ // the old conf.d/wt.fish hanging around
+ let fish_targeted = configured.iter().any(|r| r.shell == Shell::Fish);
+
+ if !fish_targeted {
+ return cleaned;
+ }
+
+ // Check for legacy conf.d file
+ let Ok(legacy_path) = Shell::legacy_fish_conf_d_path(cmd) else {
+ return cleaned;
+ };
+
+ if !legacy_path.exists() {
+ return cleaned;
+ }
+
+ // Only remove if the file contains worktrunk integration markers
+ // to avoid deleting user's custom wt.fish that isn't from worktrunk
+ let Ok(content) = fs::read_to_string(&legacy_path) else {
+ return cleaned;
+ };
+
+ if !is_worktrunk_managed_content(&content, cmd) {
+ return cleaned;
+ }
+
+ match fs::remove_file(&legacy_path) {
+ Ok(()) => {
+ cleaned.push(legacy_path);
+ }
+ Err(e) => {
+ // Warn but don't fail - the new integration will still work
+ let _ = crate::output::print(warning_message(format!(
+ "Failed to remove deprecated {}: {e}",
+ format_path_for_display(&legacy_path)
+ )));
+ }
+ }
+
+ cleaned
+}
+
pub fn handle_configure_shell(
shell_filter: Option<Shell>,
skip_confirmation: bool,
@@ -124,6 +190,7 @@ pub fn handle_configure_shell(
completion_results: completion_preview,
skipped: preview.skipped,
zsh_needs_compinit: false,
+ legacy_cleanups: Vec::new(),
});
}
@@ -136,24 +203,28 @@ pub fn handle_configure_shell(
.iter()
.any(|r| !matches!(r.action, ConfigAction::AlreadyExists));
- // If nothing needs to be changed, just return the preview results
- if !needs_shell_changes && !needs_completion_changes {
+ // For --dry-run, show preview and return without modifying anything
+ if dry_run {
+ show_install_preview(&preview.configured, &completion_preview, &cmd);
return Ok(ScanResult {
configured: preview.configured,
completion_results: completion_preview,
skipped: preview.skipped,
zsh_needs_compinit: false,
+ legacy_cleanups: Vec::new(),
});
}
- // For --dry-run, show preview and return without prompting or applying
- if dry_run {
- show_install_preview(&preview.configured, &completion_preview, &cmd);
+ // If nothing needs to be changed, still clean up legacy fish conf.d files
+ // A user might have upgraded and have both functions/wt.fish and conf.d/wt.fish
+ if !needs_shell_changes && !needs_completion_changes {
+ let legacy_cleanups = cleanup_legacy_fish_conf_d(&preview.configured, &cmd);
return Ok(ScanResult {
configured: preview.configured,
completion_results: completion_preview,
skipped: preview.skipped,
zsh_needs_compinit: false,
+ legacy_cleanups,
});
}
@@ -202,11 +273,16 @@ pub fn handle_configure_shell(
// If detection fails (None), stay silent - we can't be sure.
let zsh_needs_compinit = should_check_compinit && shell::detect_zsh_compinit() == Some(false);
+ // Clean up legacy fish conf.d file if we just installed to functions/
+ // This handles migration from the old conf.d location (issue #566)
+ let legacy_cleanups = cleanup_legacy_fish_conf_d(&result.configured, &cmd);
+
Ok(ScanResult {
configured: result.configured,
completion_results,
skipped: result.skipped,
zsh_needs_compinit,
+ legacy_cleanups,
})
}
@@ -228,12 +304,12 @@ pub fn scan_shell_configs(
for shell in shells {
let paths = shell
.config_paths(cmd)
- .map_err(|e| format!("Failed to get config paths for {}: {}", shell, e))?;
+ .map_err(|e| format!("Failed to get config paths for {shell}: {e}"))?;
// Find the first existing config file
let target_path = paths.iter().find(|p| p.exists());
- // For Fish, also check if the parent directory (conf.d/) exists
+ // For Fish, also check if the parent directory (functions/) exists
// since we create the file there rather than modifying an existing one
let has_config_location = if matches!(shell, Shell::Fish) {
paths
@@ -258,13 +334,13 @@ pub fn scan_shell_configs(
Err(e) => {
// For non-critical errors, we could continue with other shells
// but for now we'll fail fast
- return Err(format!("Failed to configure {}: {}", shell, e));
+ return Err(format!("Failed to configure {shell}: {e}"));
}
}
}
} 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
+ // For Fish, we check for functions/ directory; for others, the config file
let skipped_path = if matches!(shell, Shell::Fish) {
paths
.first()
@@ -288,7 +364,8 @@ pub fn scan_shell_configs(
configured: results,
completion_results: Vec::new(), // Completions handled separately in handle_configure_shell
skipped,
- zsh_needs_compinit: false, // Caller handles compinit detection
+ zsh_needs_compinit: false, // Caller handles compinit detection
+ legacy_cleanups: Vec::new(), // Caller handles legacy cleanup
})
}
@@ -302,12 +379,18 @@ fn configure_shell_file(
// The line we write to the config file (also used for display)
let config_line = shell.config_line(cmd);
- // For Fish, we write to a separate conf.d/ file
+ // For Fish, we write a minimal wrapper to functions/{cmd}.fish that sources the
+ // full function from the binary. This allows updates to worktrunk to automatically
+ // provide the latest wrapper logic without requiring reinstall.
if matches!(shell, Shell::Fish) {
+ let init = shell::ShellInit::with_prefix(shell, cmd.to_string());
+ let fish_wrapper = init
+ .generate_fish_wrapper()
+ .map_err(|e| format!("Failed to generate fish wrapper: {e}"))?;
return configure_fish_file(
shell,
path,
- &config_line,
+ &fish_wrapper,
dry_run,
explicit_shell,
&config_line,
@@ -427,15 +510,20 @@ fn configure_fish_file(
explicit_shell: bool,
config_line: &str,
) -> Result<Option<ConfigureResult>, String> {
- // For Fish, we write to conf.d/{cmd}.fish (separate file)
+ // For Fish, we write a minimal wrapper to functions/{cmd}.fish that sources
+ // the full function from `{cmd} config shell init fish` at runtime.
+ // Fish autoloads these files on first invocation of the command.
// Check if it already exists and has our integration
- if path.exists() {
- let existing_content = fs::read_to_string(path)
- .map_err(|e| format!("Failed to read {}: {}", format_path_for_display(path), e))?;
-
+ // Use .ok() for read errors - treat as "not configured" rather than failing
+ if let Some(existing_content) = path
+ .exists()
+ .then(|| fs::read_to_string(path).ok())
+ .flatten()
+ {
// Canonical detection: check if the file matches exactly what we write
- if existing_content.trim() == content {
+ // Trim both sides to handle trailing newlines consistently across platforms
+ if existing_content.trim() == content.trim() {
return Ok(Some(ConfigureResult {
shell,
path: path.to_path_buf(),
@@ -447,7 +535,7 @@ fn configure_fish_file(
// File doesn't exist or doesn't have our integration
// For Fish, create if parent directory exists or if explicitly targeting this shell
- // This is different from other shells because Fish uses conf.d/ which may exist
+ // This is different from other shells because Fish uses functions/ which may exist
// even if the specific wt.fish file doesn't
if !explicit_shell && !path.exists() {
// Check if parent directory exists
@@ -457,14 +545,11 @@ fn configure_fish_file(
}
if dry_run {
+ // Fish always writes the complete file (doesn't append), so always WouldCreate
return Ok(Some(ConfigureResult {
shell,
path: path.to_path_buf(),
- action: if path.exists() {
- ConfigAction::WouldAdd
- } else {
- ConfigAction::WouldCreate
- },
+ action: ConfigAction::WouldCreate,
config_line: config_line.to_string(),
}));
}
@@ -472,17 +557,12 @@ fn configure_fish_file(
// Create parent directories if they don't exist
if let Some(parent) = path.parent() {
fs::create_dir_all(parent)
- .map_err(|e| format!("Failed to create directory {}: {}", parent.display(), e))?;
+ .map_err(|e| format!("Failed to create directory {}: {e}", parent.display()))?;
}
- // Write the conditional wrapper (short one-liner that calls wt init fish | source)
- fs::write(path, format!("{}\n", content)).map_err(|e| {
- format!(
- "Failed to write to {}: {}",
- format_path_for_display(path),
- e
- )
- })?;
+ // Write the complete fish function file
+ fs::write(path, format!("{}\n", content))
+ .map_err(|e| format!("Failed to write {}: {e}", format_path_for_display(path)))?;
Ok(Some(ConfigureResult {
shell,
@@ -530,8 +610,17 @@ pub fn show_install_preview(
result.action.description(),
));
- // Show the config line that will be added with gutter
- let _ = output::print(format_bash_with_gutter(&result.config_line));
+ // Show the config content that will be added with gutter
+ // Fish: show the wrapper (it's a complete file that sources the full function)
+ // Other shells: show the one-liner that gets appended
+ let content = if matches!(shell, Shell::Fish) {
+ shell::ShellInit::with_prefix(shell, cmd.to_string())
+ .generate_fish_wrapper()
+ .unwrap_or_else(|_| result.config_line.clone())
+ } else {
+ result.config_line.clone()
+ };
+ let _ = output::print(format_bash_with_gutter(&content));
let _ = output::blank(); // Blank line after each shell block
}
@@ -575,18 +664,28 @@ pub fn show_uninstall_preview(
for result in results {
let shell = result.shell;
let path = format_path_for_display(&result.path);
- // Bash/Zsh: inline completions; Fish: separate completion file
- let what = if matches!(shell, Shell::Fish) {
- "shell extension"
+
+ // Deprecated files get a different message format
+ if let Some(canonical) = &result.superseded_by {
+ let canonical_path = format_path_for_display(canonical);
+ let _ = output::print(format!(
+ "{INFO_SYMBOL} {} {bold}{path}{bold:#} (deprecated; now using {bold}{canonical_path}{bold:#})",
+ result.action.description(),
+ ));
} else {
- "shell extension & completions"
- };
+ // Bash/Zsh: inline completions; Fish: separate completion file
+ let what = if matches!(shell, Shell::Fish) {
+ "shell extension"
+ } else {
+ "shell extension & completions"
+ };
- let _ = output::print(format!(
- "{} {} {what} for {bold}{shell}{bold:#} @ {bold}{path}{bold:#}",
- result.action.symbol(),
- result.action.description(),
- ));
+ let _ = output::print(format!(
+ "{} {} {what} for {bold}{shell}{bold:#} @ {bold}{path}{bold:#}",
+ result.action.symbol(),
+ result.action.description(),
+ ));
+ }
}
for result in completion_results {
@@ -674,7 +773,7 @@ fn prompt_yes_no() -> Result<bool, String> {
fn fish_completion_content(cmd: &str) -> String {
format!(
r#"# worktrunk completions for fish
-complete --keep-order --exclusive --command {cmd} --arguments "(test -n \"\$WORKTRUNK_BIN\"; or set -l WORKTRUNK_BIN (type -P {cmd}); COMPLETE=fish \$WORKTRUNK_BIN -- (commandline --current-process --tokenize --cut-at-cursor) (commandline --current-token))"
+complete --keep-order --exclusive --command {cmd} --arguments "(test -n \"\$WORKTRUNK_BIN\"; or set -l WORKTRUNK_BIN (type -P {cmd} 2>/dev/null); and COMPLETE=fish \$WORKTRUNK_BIN -- (commandline --current-process --tokenize --cut-at-cursor) (commandline --current-token))"
"#
)
}
@@ -700,20 +799,22 @@ pub fn process_shell_completions(
let completion_path = shell
.completion_path(cmd)
- .map_err(|e| format!("Failed to get completion path for {}: {}", shell, e))?;
+ .map_err(|e| format!("Failed to get completion path for {shell}: {e}"))?;
// Check if completions already exist with correct content
- if completion_path.exists() {
- let existing = fs::read_to_string(&completion_path)
- .map_err(|e| format!("Failed to read {}: {}", completion_path.display(), e))?;
- if existing == fish_completion {
- results.push(CompletionResult {
- shell,
- path: completion_path,
- action: ConfigAction::AlreadyExists,
- });
- continue;
- }
+ // Use .ok() for read errors - treat as "not configured" rather than failing
+ if let Some(existing) = completion_path
+ .exists()
+ .then(|| fs::read_to_string(&completion_path).ok())
+ .flatten()
+ && existing == fish_completion
+ {
+ results.push(CompletionResult {
+ shell,
+ path: completion_path,
+ action: ConfigAction::AlreadyExists,
+ });
+ continue;
}
if dry_run {
@@ -733,12 +834,12 @@ pub fn process_shell_completions(
// Create parent directory if needed
if let Some(parent) = completion_path.parent() {
fs::create_dir_all(parent)
- .map_err(|e| format!("Failed to create {}: {}", parent.display(), e))?;
+ .map_err(|e| format!("Failed to create directory {}: {e}", parent.display()))?;
}
// Write the completion file
fs::write(&completion_path, &fish_completion)
- .map_err(|e| format!("Failed to write {}: {}", completion_path.display(), e))?;
+ .map_err(|e| format!("Failed to write {}: {e}", completion_path.display()))?;
results.push(CompletionResult {
shell,
@@ -799,17 +900,29 @@ fn scan_for_uninstall(
for &shell in &shells {
let paths = shell
.config_paths(cmd)
- .map_err(|e| format!("Failed to get config paths for {}: {}", shell, e))?;
+ .map_err(|e| format!("Failed to get config paths for {shell}: {e}"))?;
- // For Fish, delete entire {cmd}.fish file
+ // For Fish, delete entire {cmd}.fish file (check both canonical and legacy locations)
if matches!(shell, Shell::Fish) {
- if let Some(fish_path) = paths.first() {
- if fish_path.exists() {
+ let mut found_any = false;
+
+ // Check canonical location (functions/)
+ // Only remove if it contains worktrunk markers to avoid deleting user's custom file
+ if let Some(fish_path) = paths.first()
+ && fish_path.exists()
+ {
+ let is_worktrunk_managed = fs::read_to_string(fish_path)
+ .map(|content| is_worktrunk_managed_content(&content, cmd))
+ .unwrap_or(false);
+
+ if is_worktrunk_managed {
+ found_any = true;
if dry_run {
results.push(UninstallResult {
shell,
path: fish_path.clone(),
action: UninstallAction::WouldRemove,
+ superseded_by: None,
});
} else {
fs::remove_file(fish_path).map_err(|e| {
@@ -823,12 +936,48 @@ fn scan_for_uninstall(
shell,
path: fish_path.clone(),
action: UninstallAction::Removed,
+ superseded_by: None,
});
}
- } else {
- not_found.push((shell, fish_path.clone()));
}
}
+
+ // Also check legacy location (conf.d/) - issue #566
+ // Only remove if it contains worktrunk markers to avoid deleting user's custom file
+ let canonical_path = paths.first().cloned();
+ if let Ok(legacy_path) = Shell::legacy_fish_conf_d_path(cmd)
+ && legacy_path.exists()
+ {
+ let is_worktrunk_managed = fs::read_to_string(&legacy_path)
+ .map(|content| is_worktrunk_managed_content(&content, cmd))
+ .unwrap_or(false);
+
+ if is_worktrunk_managed {
+ found_any = true;
+ if dry_run {
+ results.push(UninstallResult {
+ shell,
+ path: legacy_path.clone(),
+ action: UninstallAction::WouldRemove,
+ superseded_by: canonical_path.clone(),
+ });
+ } else {
+ fs::remove_file(&legacy_path).map_err(|e| {
+ format!("Failed to remove {}: {e}", legacy_path.display())
+ })?;
+ results.push(UninstallResult {
+ shell,
+ path: legacy_path,
+ action: UninstallAction::Removed,
+ superseded_by: canonical_path,
+ });
+ }
+ }
+ }
+
+ if !found_any && let Some(fish_path) = paths.first() {
+ not_found.push((shell, fish_path.clone()));
+ }
continue;
}
@@ -925,6 +1074,7 @@ fn uninstall_from_file(
shell,
path: path.to_path_buf(),
action: UninstallAction::WouldRemove,
+ superseded_by: None,
}));
}
@@ -959,6 +1109,7 @@ fn uninstall_from_file(
shell,
path: path.to_path_buf(),
action: UninstallAction::Removed,
+ superseded_by: None,
}))
}
diff --git a/src/commands/snapshots/wt__commands__configure_shell__tests__fish_completion_content.snap b/src/commands/snapshots/wt__commands__configure_shell__tests__fish_completion_content.snap
index 1dfc220f5..6fc388595 100644
--- a/src/commands/snapshots/wt__commands__configure_shell__tests__fish_completion_content.snap
+++ b/src/commands/snapshots/wt__commands__configure_shell__tests__fish_completion_content.snap
@@ -3,4 +3,4 @@ source: src/commands/configure_shell.rs
expression: "fish_completion_content(\"wt\")"
---
# worktrunk completions for fish
-complete --keep-order --exclusive --command wt --arguments "(test -n \"\$WORKTRUNK_BIN\"; or set -l WORKTRUNK_BIN (type -P wt); COMPLETE=fish \$WORKTRUNK_BIN -- (commandline --current-process --tokenize --cut-at-cursor) (commandline --current-token))"
+complete --keep-order --exclusive --command wt --arguments "(test -n \"\$WORKTRUNK_BIN\"; or set -l WORKTRUNK_BIN (type -P wt 2>/dev/null); and COMPLETE=fish \$WORKTRUNK_BIN -- (commandline --current-process --tokenize --cut-at-cursor) (commandline --current-token))"
diff --git a/src/commands/snapshots/wt__commands__configure_shell__tests__fish_completion_content_custom_cmd.snap b/src/commands/snapshots/wt__commands__configure_shell__tests__fish_completion_content_custom_cmd.snap
index dc9549aab..6b5ced400 100644
--- a/src/commands/snapshots/wt__commands__configure_shell__tests__fish_completion_content_custom_cmd.snap
+++ b/src/commands/snapshots/wt__commands__configure_shell__tests__fish_completion_content_custom_cmd.snap
@@ -3,4 +3,4 @@ source: src/commands/configure_shell.rs
expression: "fish_completion_content(\"myapp\")"
---
# worktrunk completions for fish
-complete --keep-order --exclusive --command myapp --arguments "(test -n \"\$WORKTRUNK_BIN\"; or set -l WORKTRUNK_BIN (type -P myapp); COMPLETE=fish \$WORKTRUNK_BIN -- (commandline --current-process --tokenize --cut-at-cursor) (commandline --current-token))"
+complete --keep-order --exclusive --command myapp --arguments "(test -n \"\$WORKTRUNK_BIN\"; or set -l WORKTRUNK_BIN (type -P myapp 2>/dev/null); and COMPLETE=fish \$WORKTRUNK_BIN -- (commandline --current-process --tokenize --cut-at-cursor) (commandline --current-token))"
diff --git a/src/main.rs b/src/main.rs
index bb234abbc..4979cbf03 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -908,7 +908,12 @@ fn main() {
return Ok(());
}
- let shell_count = scan_result.results.len();
+ // Count unique shells, not file results (fish may have 2 files: functions/ and legacy conf.d/)
+ let mut shells: Vec<_> =
+ scan_result.results.iter().map(|r| r.shell).collect();
+ shells.sort_by_key(|s| s.to_string());
+ shells.dedup();
+ let shell_count = shells.len();
let completion_count = scan_result.completion_results.len();
let total_changes = shell_count + completion_count;
diff --git a/src/output/shell_integration.rs b/src/output/shell_integration.rs
index 0f0acdec5..c3fa97d07 100644
--- a/src/output/shell_integration.rs
+++ b/src/output/shell_integration.rs
@@ -123,15 +123,20 @@ fn compute_shell_warning_reason_inner(
.and_then(|s| s.to_str())
.unwrap_or(invoked);
- // Check if the only difference is .exe suffix (case-insensitive for Windows)
- let invoked_lower = invoked_name.to_lowercase();
- let wraps_lower = wraps.to_lowercase();
- if invoked_lower == format!("{wraps_lower}.exe") {
- // Windows .exe mismatch - give targeted advice
- cformat!(
- "ran <bold>{invoked_name}</>; use <bold>{wraps}</> (without .exe) for auto-cd"
- )
- } else if invoked_name == wraps {
+ // Windows: check if the only difference is .exe suffix (case-insensitive)
+ #[cfg(windows)]
+ {
+ let invoked_lower = invoked_name.to_lowercase();
+ let wraps_lower = wraps.to_lowercase();
+ if invoked_lower == format!("{wraps_lower}.exe") {
+ // Windows .exe mismatch - give targeted advice
+ return cformat!(
+ "ran <bold>{invoked_name}</>; use <bold>{wraps}</> (without .exe) for auto-cd"
+ );
+ }
+ }
+
+ if invoked_name == wraps {
// Filename matches but full path differs - show full path for clarity
// (e.g., "./target/debug/wt" vs "wt" - the path IS the useful info)
cformat!("ran <bold>{invoked}</>; shell integration wraps <bold>{wraps}</>")
@@ -246,6 +251,21 @@ pub fn print_shell_install_result(
}
}
+ // Show legacy file cleanups (migration from conf.d to functions)
+ for legacy_path in &scan_result.legacy_cleanups {
+ let old_path = format_path_for_display(legacy_path);
+ // Find the new canonical path from the configured results
+ let new_path = scan_result
+ .configured
+ .iter()
+ .find(|r| r.shell == Shell::Fish)
+ .map(|r| format_path_for_display(&r.path))
+ .unwrap_or_else(|| "~/.config/fish/functions/".to_string());
+ super::print(info_message(cformat!(
+ "Removed <bold>{old_path}</> (deprecated; now using <bold>{new_path}</>)"
+ )))?;
+ }
+
// Show skipped shells
print_skipped_shells(&scan_result.skipped)?;
diff --git a/src/shell.rs b/src/shell.rs
index 2906b5fb9..d3723355a 100644
--- a/src/shell.rs
+++ b/src/shell.rs
@@ -445,7 +445,10 @@ pub fn scan_for_detection_details(cmd: &str) -> Result<Vec<FileDetectionResult>,
.map(PathBuf::from)
.unwrap_or_else(|_| home.clone())
.join(".zshrc"),
- // Fish conf.d
+ // Fish functions/ (current location)
+ home.join(".config/fish/functions")
+ .join(format!("{cmd}.fish")),
+ // Fish conf.d (legacy location - for detecting existing installs)
home.join(".config/fish/conf.d").join(format!("{cmd}.fish")),
];
@@ -486,7 +489,7 @@ pub enum Shell {
impl Shell {
/// Returns the config file paths for this shell.
///
- /// The `cmd` parameter affects the Fish conf.d filename (e.g., `wt.fish` or `git-wt.fish`).
+ /// The `cmd` parameter affects the Fish functions filename (e.g., `wt.fish` or `git-wt.fish`).
/// Returns paths in order of preference. The first existing file should be used.
pub fn config_paths(&self, cmd: &str) -> Result<Vec<PathBuf>, std::io::Error> {
let home = home_dir_required()?;
@@ -503,12 +506,14 @@ impl Shell {
vec![zdotdir.join(".zshrc")]
}
Self::Fish => {
- // For fish, we write to conf.d/ which is auto-sourced
- // Filename includes prefix to avoid conflicts (e.g., wt.fish, git-wt.fish)
+ // For fish, we write to functions/ which is autoloaded on first use.
+ // This ensures PATH is fully configured before our function loads,
+ // fixing the issue where Homebrew PATH setup in config.fish runs
+ // after conf.d/ files. See: https://github.com/max-sixty/worktrunk/issues/566
vec![
home.join(".config")
.join("fish")
- .join("conf.d")
+ .join("functions")
.join(format!("{}.fish", cmd)),
]
}
@@ -516,6 +521,21 @@ impl Shell {
})
}
+ /// Returns the legacy fish conf.d path for cleanup purposes.
+ ///
+ /// Previously, fish shell integration was installed to `~/.config/fish/conf.d/{cmd}.fish`.
+ /// This caused issues with Homebrew PATH setup (see issue #566). We now install to
+ /// `functions/{cmd}.fish` instead. This method returns the legacy path so install/uninstall
+ /// can clean it up.
+ pub fn legacy_fish_conf_d_path(cmd: &str) -> Result<PathBuf, std::io::Error> {
+ let home = home_dir_required()?;
+ Ok(home
+ .join(".config")
+ .join("fish")
+ .join("conf.d")
+ .join(format!("{}.fish", cmd)))
+ }
+
/// Returns the path to the native completion directory for this shell.
///
/// The `cmd` parameter affects the completion filename (e.g., `wt.fish` or `git-wt.fish`).
@@ -620,7 +640,7 @@ impl ShellInit {
Self { shell, cmd }
}
- /// Generate shell integration code
+ /// Generate shell integration code (for `wt config shell init`)
pub fn generate(&self) -> Result<String, askama::Error> {
match self.shell {
Shell::Bash => {
@@ -644,6 +664,15 @@ impl ShellInit {
}
}
}
+
+ /// Generate fish wrapper code (for `wt config shell install fish`)
+ ///
+ /// This generates a minimal wrapper that sources the full function from the binary.
+ /// Unlike `generate()` which outputs the full function, this wrapper auto-updates.
+ pub fn generate_fish_wrapper(&self) -> Result<String, askama::Error> {
+ let template = FishWrapperTemplate { cmd: &self.cmd };
+ template.render()
+ }
}
/// Bash shell template
@@ -661,13 +690,24 @@ struct ZshTemplate<'a> {
cmd: &'a str,
}
-/// Fish shell template
+/// Fish shell template (full function for `wt config shell init fish`)
#[derive(Template)]
#[template(path = "fish.fish", escape = "none")]
struct FishTemplate<'a> {
cmd: &'a str,
}
+/// Fish wrapper template (minimal wrapper for `functions/wt.fish`)
+///
+/// This wrapper is autoloaded by fish and sources the full function from the binary.
+/// Unlike the full FishTemplate, this allows updates to worktrunk to automatically
+/// provide the latest wrapper logic without requiring `wt config shell install`.
+#[derive(Template)]
+#[template(path = "fish_wrapper.fish", escape = "none")]
+struct FishWrapperTemplate<'a> {
+ cmd: &'a str,
+}
+
/// PowerShell template
#[derive(Template)]
#[template(path = "powershell.ps1", escape = "none")]
diff --git a/src/snapshots/worktrunk__shell__tests__init_fish.snap b/src/snapshots/worktrunk__shell__tests__init_fish.snap
index d178aa6d3..eb7a899d9 100644
--- a/src/snapshots/worktrunk__shell__tests__init_fish.snap
+++ b/src/snapshots/worktrunk__shell__tests__init_fish.snap
@@ -3,47 +3,50 @@ source: src/shell.rs
expression: output
---
# worktrunk shell integration for fish
+#
+# This is the full function definition, output by `wt config shell init fish`.
+# It's sourced at runtime by the wrapper in ~/.config/fish/functions/wt.fish.
+
+# Override wt command with file-based directive passing.
+# Creates a temp file, passes path via WORKTRUNK_DIRECTIVE_FILE, evals it after.
+# WORKTRUNK_BIN can override the binary path (for testing dev builds).
+#
+# Note: We use `eval (cat ... | string collect)` instead of `source` because:
+# 1. fish's `source` doesn't propagate exit codes to the parent function
+# 2. `eval (cat ...)` without `string collect` splits on newlines, breaking multiline directives
+# With `string collect`, we get proper exit code propagation for cd and other directives.
+function wt
+ set -l use_source false
+ set -l args
+
+ for arg in $argv
+ if test "$arg" = "--source"; set use_source true; else; set -a args $arg; end
+ end
-# Only initialize if wt is available (in PATH or via WORKTRUNK_BIN)
-if type -q wt; or test -n "$WORKTRUNK_BIN"
-
- # Override wt command with file-based directive passing.
- # Creates a temp file, passes path via WORKTRUNK_DIRECTIVE_FILE, evals it after.
- # WORKTRUNK_BIN can override the binary path (for testing dev builds).
- #
- # Note: We use `eval (cat ... | string collect)` instead of `source` because:
- # 1. fish's `source` doesn't propagate `exit` to the parent function
- # 2. `eval (cat ...)` without `string collect` splits on newlines, breaking multiline directives
- # With `string collect`, `exit 42` properly exits the function with code 42.
- function wt
- set -l use_source false
- set -l args
-
- for arg in $argv
- if test "$arg" = "--source"; set use_source true; else; set -a args $arg; end
- end
-
- test -n "$WORKTRUNK_BIN"; or set -l WORKTRUNK_BIN (type -P wt)
- set -l directive_file (mktemp)
+ test -n "$WORKTRUNK_BIN"; or set -l WORKTRUNK_BIN (type -P wt 2>/dev/null)
+ if test -z "$WORKTRUNK_BIN"
+ echo "wt: command not found" >&2
+ return 127
+ end
+ set -l directive_file (mktemp)
- # --source: use cargo run (builds from source)
- if test $use_source = true
- WORKTRUNK_DIRECTIVE_FILE=$directive_file cargo run --bin wt --quiet -- $args
- else
- WORKTRUNK_DIRECTIVE_FILE=$directive_file command $WORKTRUNK_BIN $args
- end
- set -l exit_code $status
+ # --source: use cargo run (builds from source)
+ if test $use_source = true
+ WORKTRUNK_DIRECTIVE_FILE=$directive_file cargo run --bin wt --quiet -- $args
+ else
+ WORKTRUNK_DIRECTIVE_FILE=$directive_file command $WORKTRUNK_BIN $args
+ end
+ set -l exit_code $status
- if test -s "$directive_file"
- eval (cat "$directive_file" | string collect)
- if test $exit_code -eq 0
- set exit_code $status
- end
+ if test -s "$directive_file"
+ eval (cat "$directive_file" | string collect)
+ if test $exit_code -eq 0
+ set exit_code $status
end
-
- rm -f "$directive_file"
- return $exit_code
end
- # Completions are in ~/.config/fish/completions/wt.fish (installed by `wt config shell install`)
+ rm -f "$directive_file"
+ return $exit_code
end
+
+# Completions are in ~/.config/fish/completions/wt.fish (installed by `wt config shell install`)
diff --git a/templates/fish.fish b/templates/fish.fish
index 61f2edd0e..dd1a30fad 100644
--- a/templates/fish.fish
+++ b/templates/fish.fish
@@ -1,45 +1,48 @@
# worktrunk shell integration for fish
+#
+# This is the full function definition, output by `{{ cmd }} config shell init fish`.
+# It's sourced at runtime by the wrapper in ~/.config/fish/functions/{{ cmd }}.fish.
+
+# Override {{ cmd }} command with file-based directive passing.
+# Creates a temp file, passes path via WORKTRUNK_DIRECTIVE_FILE, evals it after.
+# WORKTRUNK_BIN can override the binary path (for testing dev builds).
+#
+# Note: We use `eval (cat ... | string collect)` instead of `source` because:
+# 1. fish's `source` doesn't propagate exit codes to the parent function
+# 2. `eval (cat ...)` without `string collect` splits on newlines, breaking multiline directives
+# With `string collect`, we get proper exit code propagation for cd and other directives.
+function {{ cmd }}
+ set -l use_source false
+ set -l args
+
+ for arg in $argv
+ if test "$arg" = "--source"; set use_source true; else; set -a args $arg; end
+ end
-# Only initialize if {{ cmd }} is available (in PATH or via WORKTRUNK_BIN)
-if type -q {{ cmd }}; or test -n "$WORKTRUNK_BIN"
-
- # Override {{ cmd }} command with file-based directive passing.
- # Creates a temp file, passes path via WORKTRUNK_DIRECTIVE_FILE, evals it after.
- # WORKTRUNK_BIN can override the binary path (for testing dev builds).
- #
- # Note: We use `eval (cat ... | string collect)` instead of `source` because:
- # 1. fish's `source` doesn't propagate `exit` to the parent function
- # 2. `eval (cat ...)` without `string collect` splits on newlines, breaking multiline directives
- # With `string collect`, `exit 42` properly exits the function with code 42.
- function {{ cmd }}
- set -l use_source false
- set -l args
-
- for arg in $argv
- if test "$arg" = "--source"; set use_source true; else; set -a args $arg; end
- end
-
- test -n "$WORKTRUNK_BIN"; or set -l WORKTRUNK_BIN (type -P {{ cmd }})
- set -l directive_file (mktemp)
+ test -n "$WORKTRUNK_BIN"; or set -l WORKTRUNK_BIN (type -P {{ cmd }} 2>/dev/null)
+ if test -z "$WORKTRUNK_BIN"
+ echo "{{ cmd }}: command not found" >&2
+ return 127
+ end
+ set -l directive_file (mktemp)
- # --source: use cargo run (builds from source)
- if test $use_source = true
- WORKTRUNK_DIRECTIVE_FILE=$directive_file cargo run --bin {{ cmd }} --quiet -- $args
- else
- WORKTRUNK_DIRECTIVE_FILE=$directive_file command $WORKTRUNK_BIN $args
- end
- set -l exit_code $status
+ # --source: use cargo run (builds from source)
+ if test $use_source = true
+ WORKTRUNK_DIRECTIVE_FILE=$directive_file cargo run --bin {{ cmd }} --quiet -- $args
+ else
+ WORKTRUNK_DIRECTIVE_FILE=$directive_file command $WORKTRUNK_BIN $args
+ end
+ set -l exit_code $status
- if test -s "$directive_file"
- eval (cat "$directive_file" | string collect)
- if test $exit_code -eq 0
- set exit_code $status
- end
+ if test -s "$directive_file"
+ eval (cat "$directive_file" | string collect)
+ if test $exit_code -eq 0
+ set exit_code $status
end
-
- rm -f "$directive_file"
- return $exit_code
end
- # Completions are in ~/.config/fish/completions/wt.fish (installed by `wt config shell install`)
+ rm -f "$directive_file"
+ return $exit_code
end
+
+# Completions are in ~/.config/fish/completions/{{ cmd }}.fish (installed by `{{ cmd }} config shell install`)
diff --git a/templates/fish_wrapper.fish b/templates/fish_wrapper.fish
new file mode 100644
index 000000000..72a7a37c3
--- /dev/null
+++ b/templates/fish_wrapper.fish
@@ -0,0 +1,15 @@
+# worktrunk shell integration for fish
+# Sources full integration from binary on first use.
+# Docs: https://worktrunk.dev/docs/shell-integration
+# Check: {{ cmd }} config show | Uninstall: {{ cmd }} config shell uninstall
+
+function {{ cmd }}
+ command {{ cmd }} config shell init fish | source
+ # Check both command exit code ($pipestatus[1]) and source exit code ($pipestatus[2])
+ # If source fails, the function isn't replaced and we'd infinite-loop calling ourselves
+ set -l wt_status $pipestatus[1]
+ set -l source_status $pipestatus[2]
+ test $wt_status -eq 0; or return $wt_status
+ test $source_status -eq 0; or return $source_status
+ {{ cmd }} $argv
+end
diff --git a/tests/integration_tests/configure_shell.rs b/tests/integration_tests/configure_shell.rs
index e98f8d24e..1764ffcdf 100644
--- a/tests/integration_tests/configure_shell.rs
+++ b/tests/integration_tests/configure_shell.rs
@@ -34,7 +34,7 @@ fn test_configure_shell_with_yes(repo: TestRepo, temp_home: TempDir) {
----- stderr -----
✓ Added shell extension & completions for zsh @ ~/.zshrc
↳ Skipped bash; ~/.bashrc not found
- ↳ Skipped fish; ~/.config/fish/conf.d not found
+ ↳ Skipped fish; ~/.config/fish/functions not found
✓ Configured 1 shell
▲ Completions require compinit; add to ~/.zshrc before the wt line:
@@ -150,7 +150,7 @@ fn test_configure_shell_fish(repo: TestRepo, temp_home: TempDir) {
----- stdout -----
----- stderr -----
- ✓ Created shell extension for fish @ ~/.config/fish/conf.d/wt.fish
+ ✓ Created shell extension for fish @ ~/.config/fish/functions/wt.fish
✓ Created completions for fish @ ~/.config/fish/completions/wt.fish
✓ Configured 1 shell
@@ -159,29 +159,62 @@ fn test_configure_shell_fish(repo: TestRepo, temp_home: TempDir) {
});
// Verify the fish conf.d file was created
- let fish_config = temp_home.path().join(".config/fish/conf.d/wt.fish");
+ let fish_config = temp_home.path().join(".config/fish/functions/wt.fish");
assert!(fish_config.exists());
let content = fs::read_to_string(&fish_config).unwrap();
assert!(
- content.trim() == "if type -q wt; command wt config shell init fish | source; end",
- "Should contain conditional wrapper: {}",
+ content.contains("function wt"),
+ "Should contain function definition: {}",
content
);
}
-/// Fish completions are now inline in the init script, so no separate file is needed
+/// Test install dry-run shows preview with gutter-formatted config content
+#[rstest]
+fn test_configure_shell_fish_dry_run(repo: TestRepo, temp_home: TempDir) {
+ // Create fish functions directory (but no wt.fish - so it will be "created")
+ let functions = temp_home.path().join(".config/fish/functions");
+ fs::create_dir_all(&functions).unwrap();
+
+ let settings = setup_home_snapshot_settings(&temp_home);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.configure_wt_cmd(&mut cmd);
+ set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("SHELL", "/bin/fish");
+ cmd.arg("config")
+ .arg("shell")
+ .arg("install")
+ .arg("fish")
+ .arg("--dry-run")
+ .current_dir(repo.root_path());
+
+ // Dry-run should show "Will create" and the actual content in gutter
+ assert_cmd_snapshot!(cmd);
+ });
+
+ // Verify no files were actually created
+ let fish_config = functions.join("wt.fish");
+ assert!(
+ !fish_config.exists(),
+ "Dry-run should not create files: {:?}",
+ fish_config
+ );
+}
+
+/// Test that installing when extension exists shows "Already configured"
#[rstest]
fn test_configure_shell_fish_extension_exists(repo: TestRepo, temp_home: TempDir) {
- // Create fish conf.d directory with wt.fish (extension exists)
- let conf_d = temp_home.path().join(".config/fish/conf.d");
- fs::create_dir_all(&conf_d).unwrap();
- let fish_config = conf_d.join("wt.fish");
- fs::write(
- &fish_config,
- "if type -q wt; command wt config shell init fish | source; end",
- )
- .unwrap();
+ // Create fish functions directory with wt.fish (extension exists at new canonical location)
+ let functions = temp_home.path().join(".config/fish/functions");
+ fs::create_dir_all(&functions).unwrap();
+ let fish_config = functions.join("wt.fish");
+ // Write the exact wrapper content that install would create
+ let init =
+ worktrunk::shell::ShellInit::with_prefix(worktrunk::shell::Shell::Fish, "wt".to_string());
+ let wrapper_content = init.generate_fish_wrapper().unwrap();
+ fs::write(&fish_config, format!("{}\n", wrapper_content)).unwrap();
let settings = setup_home_snapshot_settings(&temp_home);
settings.bind(|| {
@@ -196,15 +229,15 @@ fn test_configure_shell_fish_extension_exists(repo: TestRepo, temp_home: TempDir
.arg("--yes")
.current_dir(repo.root_path());
- // Fish completions are inline in the init script, so when extension exists,
- // it should say "All shells already configured"
+ // Fish shell extension exists but completions are in a separate file.
+ // Shell extension shows as "Already configured", completions show as "Created".
assert_cmd_snapshot!(cmd, @"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
- ○ Already configured shell extension for fish @ ~/.config/fish/conf.d/wt.fish
+ ○ Already configured shell extension for fish @ ~/.config/fish/functions/wt.fish
✓ Created completions for fish @ ~/.config/fish/completions/wt.fish
✓ Configured 1 shell
@@ -226,15 +259,15 @@ fn test_configure_shell_fish_extension_exists(repo: TestRepo, temp_home: TempDir
#[rstest]
fn test_configure_shell_fish_all_already_configured(repo: TestRepo, temp_home: TempDir) {
- // Create fish conf.d directory with wt.fish (extension exists)
- let conf_d = temp_home.path().join(".config/fish/conf.d");
- fs::create_dir_all(&conf_d).unwrap();
- let fish_config = conf_d.join("wt.fish");
- fs::write(
- &fish_config,
- "if type -q wt; command wt config shell init fish | source; end",
- )
- .unwrap();
+ // Create fish functions directory with wt.fish (extension exists at new canonical location)
+ let functions = temp_home.path().join(".config/fish/functions");
+ fs::create_dir_all(&functions).unwrap();
+ let fish_config = functions.join("wt.fish");
+ // Write the exact wrapper content that install would create
+ let init =
+ worktrunk::shell::ShellInit::with_prefix(worktrunk::shell::Shell::Fish, "wt".to_string());
+ let wrapper_content = init.generate_fish_wrapper().unwrap();
+ fs::write(&fish_config, format!("{}\n", wrapper_content)).unwrap();
// Also create completions file
let completions_d = temp_home.path().join(".config/fish/completions");
@@ -260,6 +293,297 @@ fn test_configure_shell_fish_all_already_configured(repo: TestRepo, temp_home: T
});
}
+/// Test that installing fish shell integration cleans up legacy conf.d file
+///
+/// Before issue #566, fish integration was installed to conf.d/wt.fish.
+/// Now it installs to functions/wt.fish. This test ensures we clean up the old location.
+#[rstest]
+fn test_configure_shell_fish_legacy_conf_d_cleanup(repo: TestRepo, temp_home: TempDir) {
+ // Create legacy conf.d file (old location)
+ let conf_d = temp_home.path().join(".config/fish/conf.d");
+ fs::create_dir_all(&conf_d).unwrap();
+ let legacy_file = conf_d.join("wt.fish");
+ // Use realistic content with worktrunk marker so it's detected as worktrunk-managed
+ fs::write(&legacy_file, "wt config shell init fish | source").unwrap();
+
+ let settings = setup_home_snapshot_settings(&temp_home);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.configure_wt_cmd(&mut cmd);
+ set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("SHELL", "/bin/fish");
+ cmd.arg("config")
+ .arg("shell")
+ .arg("install")
+ .arg("fish")
+ .arg("--yes")
+ .current_dir(repo.root_path());
+
+ // Should create new file and clean up legacy
+ assert_cmd_snapshot!(cmd);
+ });
+
+ // Verify new location exists
+ let new_file = temp_home.path().join(".config/fish/functions/wt.fish");
+ assert!(
+ new_file.exists(),
+ "Should create functions/wt.fish: {:?}",
+ new_file
+ );
+
+ // Verify legacy location was cleaned up
+ assert!(
+ !legacy_file.exists(),
+ "Should remove legacy conf.d/wt.fish: {:?}",
+ legacy_file
+ );
+}
+
+/// Test that legacy cleanup happens even when new file already exists with correct content
+///
+/// This handles the case where:
+/// 1. User had old conf.d/wt.fish (pre-#566)
+/// 2. User manually created functions/wt.fish with correct content
+/// 3. User runs `wt config shell install fish`
+///
+/// The legacy file should still be cleaned up even though install reports "Already configured"
+#[rstest]
+fn test_configure_shell_fish_legacy_cleanup_even_when_already_exists(
+ repo: TestRepo,
+ temp_home: TempDir,
+) {
+ // Create functions/wt.fish with the EXACT content that install would create
+ let functions = temp_home.path().join(".config/fish/functions");
+ fs::create_dir_all(&functions).unwrap();
+ let new_file = functions.join("wt.fish");
+ let init =
+ worktrunk::shell::ShellInit::with_prefix(worktrunk::shell::Shell::Fish, "wt".to_string());
+ let wrapper_content = init.generate_fish_wrapper().unwrap();
+ fs::write(&new_file, format!("{}\n", wrapper_content)).unwrap();
+
+ // Also create completions (so it reports "all already configured")
+ let completions_d = temp_home.path().join(".config/fish/completions");
+ fs::create_dir_all(&completions_d).unwrap();
+ fs::write(completions_d.join("wt.fish"), "# completions").unwrap();
+
+ // Create legacy conf.d file (old location that should be cleaned up)
+ let conf_d = temp_home.path().join(".config/fish/conf.d");
+ fs::create_dir_all(&conf_d).unwrap();
+ let legacy_file = conf_d.join("wt.fish");
+ // Use realistic content with worktrunk marker so it's detected as worktrunk-managed
+ fs::write(&legacy_file, "wt config shell init fish | source").unwrap();
+
+ let settings = setup_home_snapshot_settings(&temp_home);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.configure_wt_cmd(&mut cmd);
+ set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("SHELL", "/bin/fish");
+ cmd.arg("config")
+ .arg("shell")
+ .arg("install")
+ .arg("fish")
+ .arg("--yes")
+ .current_dir(repo.root_path());
+
+ // Should report "Already configured" but still clean up legacy
+ assert_cmd_snapshot!(cmd);
+ });
+
+ // The key assertion: legacy file should be removed even though new file already existed
+ assert!(
+ !legacy_file.exists(),
+ "Should remove legacy conf.d/wt.fish even when functions/wt.fish already exists: {:?}",
+ legacy_file
+ );
+
+ // New file should still exist
+ assert!(
+ new_file.exists(),
+ "Should preserve existing functions/wt.fish: {:?}",
+ new_file
+ );
+}
+
+/// Test that uninstalling fish shell integration also cleans up legacy conf.d file
+///
+/// If a user has the old conf.d/wt.fish file, uninstall should remove it too.
+#[rstest]
+fn test_uninstall_shell_fish_legacy_conf_d_cleanup(repo: TestRepo, temp_home: TempDir) {
+ // Create both new location (functions) and legacy location (conf.d)
+ let functions = temp_home.path().join(".config/fish/functions");
+ fs::create_dir_all(&functions).unwrap();
+ let new_file = functions.join("wt.fish");
+ // Write the exact wrapper content that install would create
+ let init =
+ worktrunk::shell::ShellInit::with_prefix(worktrunk::shell::Shell::Fish, "wt".to_string());
+ let wrapper_content = init.generate_fish_wrapper().unwrap();
+ fs::write(&new_file, format!("{}\n", wrapper_content)).unwrap();
+
+ let conf_d = temp_home.path().join(".config/fish/conf.d");
+ fs::create_dir_all(&conf_d).unwrap();
+ let legacy_file = conf_d.join("wt.fish");
+ // Legacy content from main branch
+ fs::write(&legacy_file, "wt config shell init fish | source").unwrap();
+
+ // Also create completions
+ let completions_d = temp_home.path().join(".config/fish/completions");
+ fs::create_dir_all(&completions_d).unwrap();
+ let completions_file = completions_d.join("wt.fish");
+ fs::write(&completions_file, "# completions").unwrap();
+
+ let settings = setup_home_snapshot_settings(&temp_home);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.configure_wt_cmd(&mut cmd);
+ set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("SHELL", "/bin/fish");
+ cmd.arg("config")
+ .arg("shell")
+ .arg("uninstall")
+ .arg("fish")
+ .arg("--yes")
+ .current_dir(repo.root_path());
+
+ // Should remove both new and legacy files
+ assert_cmd_snapshot!(cmd);
+ });
+
+ // Verify both locations were cleaned up
+ assert!(
+ !new_file.exists(),
+ "Should remove functions/wt.fish: {:?}",
+ new_file
+ );
+ assert!(
+ !legacy_file.exists(),
+ "Should remove legacy conf.d/wt.fish: {:?}",
+ legacy_file
+ );
+ assert!(
+ !completions_file.exists(),
+ "Should remove completions/wt.fish: {:?}",
+ completions_file
+ );
+}
+
+/// Test that --dry-run does NOT delete legacy fish conf.d file
+///
+/// Regression test: Previously, --dry-run could delete the legacy file because
+/// cleanup ran before the dry_run check. This must never happen.
+#[rstest]
+fn test_configure_shell_fish_dry_run_does_not_delete_legacy(repo: TestRepo, temp_home: TempDir) {
+ // Create functions/wt.fish with correct content (already configured)
+ let functions = temp_home.path().join(".config/fish/functions");
+ fs::create_dir_all(&functions).unwrap();
+ let new_file = functions.join("wt.fish");
+ let init =
+ worktrunk::shell::ShellInit::with_prefix(worktrunk::shell::Shell::Fish, "wt".to_string());
+ let wrapper_content = init.generate_fish_wrapper().unwrap();
+ fs::write(&new_file, format!("{}\n", wrapper_content)).unwrap();
+
+ // Create completions (so it reports "all already configured")
+ let completions_d = temp_home.path().join(".config/fish/completions");
+ fs::create_dir_all(&completions_d).unwrap();
+ fs::write(completions_d.join("wt.fish"), "# completions").unwrap();
+
+ // Create legacy conf.d file that should NOT be deleted in dry-run mode
+ let conf_d = temp_home.path().join(".config/fish/conf.d");
+ fs::create_dir_all(&conf_d).unwrap();
+ let legacy_file = conf_d.join("wt.fish");
+ fs::write(&legacy_file, "wt config shell init fish | source").unwrap();
+
+ let settings = setup_home_snapshot_settings(&temp_home);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.configure_wt_cmd(&mut cmd);
+ set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("SHELL", "/bin/fish");
+ cmd.arg("config")
+ .arg("shell")
+ .arg("install")
+ .arg("fish")
+ .arg("--dry-run")
+ .current_dir(repo.root_path());
+
+ assert_cmd_snapshot!(cmd);
+ });
+
+ // CRITICAL: Legacy file must still exist after --dry-run
+ assert!(
+ legacy_file.exists(),
+ "--dry-run must NOT delete legacy conf.d/wt.fish: {:?}",
+ legacy_file
+ );
+
+ // New file should still exist too
+ assert!(
+ new_file.exists(),
+ "functions/wt.fish should be preserved: {:?}",
+ new_file
+ );
+}
+
+/// Test that detection finds fish integration in legacy conf.d location
+///
+/// `wt config show` should detect shell integration whether it's in the
+/// old conf.d location or the new functions location.
+#[rstest]
+fn test_config_show_detects_fish_legacy_conf_d(mut repo: TestRepo, temp_home: TempDir) {
+ // Create ONLY the legacy conf.d file (simulating user who installed before #566)
+ let conf_d = temp_home.path().join(".config/fish/conf.d");
+ fs::create_dir_all(&conf_d).unwrap();
+ let legacy_file = conf_d.join("wt.fish");
+ // Write content that matches our detection pattern (old-style init sourcing)
+ fs::write(&legacy_file, "wt config shell init fish | source").unwrap();
+
+ // Mock claude as not found (consistent across environments)
+ repo.setup_mock_ci_tools_unauthenticated();
+
+ let settings = setup_home_snapshot_settings(&temp_home);
+ settings.bind(|| {
+ let mut cmd = repo.wt_command();
+ set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("SHELL", "/bin/fish");
+ cmd.arg("config").arg("show").current_dir(repo.root_path());
+
+ assert_cmd_snapshot!(cmd);
+ });
+}
+
+/// Test config show when functions/ exists but wt.fish doesn't, with legacy conf.d
+///
+/// This tests a different code path than test_config_show_detects_fish_legacy_conf_d:
+/// - That test: functions/ doesn't exist -> fish is "skipped"
+/// - This test: functions/ exists but empty -> fish is "configured" with WouldCreate
+///
+/// Both should show the migration hint for the legacy conf.d location.
+#[rstest]
+fn test_config_show_fish_legacy_with_functions_dir(mut repo: TestRepo, temp_home: TempDir) {
+ // Create functions/ directory (empty - no wt.fish)
+ let functions = temp_home.path().join(".config/fish/functions");
+ fs::create_dir_all(&functions).unwrap();
+
+ // Create legacy conf.d file
+ let conf_d = temp_home.path().join(".config/fish/conf.d");
+ fs::create_dir_all(&conf_d).unwrap();
+ let legacy_file = conf_d.join("wt.fish");
+ fs::write(&legacy_file, "wt config shell init fish | source").unwrap();
+
+ // Mock claude as not found
+ repo.setup_mock_ci_tools_unauthenticated();
+
+ let settings = setup_home_snapshot_settings(&temp_home);
+ settings.bind(|| {
+ let mut cmd = repo.wt_command();
+ set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("SHELL", "/bin/fish");
+ cmd.arg("config").arg("show").current_dir(repo.root_path());
+
+ assert_cmd_snapshot!(cmd);
+ });
+}
+
#[rstest]
fn test_configure_shell_no_files(repo: TestRepo, temp_home: TempDir) {
let settings = setup_home_snapshot_settings(&temp_home);
@@ -282,7 +606,7 @@ fn test_configure_shell_no_files(repo: TestRepo, temp_home: TempDir) {
----- stderr -----
↳ Skipped bash; ~/.bashrc not found
↳ Skipped zsh; ~/.zshrc not found
- ↳ Skipped fish; ~/.config/fish/conf.d not found
+ ↳ Skipped fish; ~/.config/fish/functions not found
✗ No shell config files found
");
});
@@ -318,7 +642,7 @@ fn test_configure_shell_multiple_configs(repo: TestRepo, temp_home: TempDir) {
----- stderr -----
✓ Added shell extension & completions for bash @ ~/.bashrc
✓ Added shell extension & completions for zsh @ ~/.zshrc
- ↳ Skipped fish; ~/.config/fish/conf.d not found
+ ↳ Skipped fish; ~/.config/fish/functions not found
✓ Configured 2 shells
▲ Completions require compinit; add to ~/.zshrc before the wt line:
@@ -377,7 +701,7 @@ fn test_configure_shell_mixed_states(repo: TestRepo, temp_home: TempDir) {
----- stderr -----
○ Already configured shell extension & completions for bash @ ~/.bashrc
✓ Added shell extension & completions for zsh @ ~/.zshrc
- ↳ Skipped fish; ~/.config/fish/conf.d not found
+ ↳ Skipped fish; ~/.config/fish/functions not found
✓ Configured 1 shell
▲ Completions require compinit; add to ~/.zshrc before the wt line:
@@ -432,7 +756,7 @@ fn test_uninstall_shell(repo: TestRepo, temp_home: TempDir) {
----- stderr -----
✓ Removed shell extension & completions for zsh @ ~/.zshrc
↳ No bash shell extension & completions in ~/.bashrc
- ↳ No fish shell extension in ~/.config/fish/conf.d/wt.fish
+ ↳ No fish shell extension in ~/.config/fish/functions/wt.fish
↳ No fish completions in ~/.config/fish/completions/wt.fish
✓ Removed integration from 1 shell
@@ -488,7 +812,7 @@ fn test_uninstall_shell_multiple(repo: TestRepo, temp_home: TempDir) {
----- stderr -----
✓ Removed shell extension & completions for bash @ ~/.bashrc
✓ Removed shell extension & completions for zsh @ ~/.zshrc
- ↳ No fish shell extension in ~/.config/fish/conf.d/wt.fish
+ ↳ No fish shell extension in ~/.config/fish/functions/wt.fish
↳ No fish completions in ~/.config/fish/completions/wt.fish
✓ Removed integration from 2 shells
@@ -542,15 +866,15 @@ fn test_uninstall_shell_not_found(repo: TestRepo, temp_home: TempDir) {
#[rstest]
fn test_uninstall_shell_fish(repo: TestRepo, temp_home: TempDir) {
- // Create fish conf.d directory with wt.fish
- let conf_d = temp_home.path().join(".config/fish/conf.d");
- fs::create_dir_all(&conf_d).unwrap();
- let fish_config = conf_d.join("wt.fish");
- fs::write(
- &fish_config,
- "if type -q wt; command wt config shell init fish | source; end\n",
- )
- .unwrap();
+ // Create fish functions directory with wt.fish (new canonical location)
+ let functions = temp_home.path().join(".config/fish/functions");
+ fs::create_dir_all(&functions).unwrap();
+ let fish_config = functions.join("wt.fish");
+ // Write the exact wrapper content that install would create
+ let init =
+ worktrunk::shell::ShellInit::with_prefix(worktrunk::shell::Shell::Fish, "wt".to_string());
+ let wrapper_content = init.generate_fish_wrapper().unwrap();
+ fs::write(&fish_config, format!("{}\n", wrapper_content)).unwrap();
let settings = setup_home_snapshot_settings(&temp_home);
settings.bind(|| {
@@ -571,7 +895,7 @@ fn test_uninstall_shell_fish(repo: TestRepo, temp_home: TempDir) {
----- stdout -----
----- stderr -----
- ✓ Removed shell extension for fish @ ~/.config/fish/conf.d/wt.fish
+ ✓ Removed shell extension for fish @ ~/.config/fish/functions/wt.fish
✓ Removed integration from 1 shell
↳ Restart shell to complete uninstall
@@ -784,7 +1108,7 @@ fn test_configure_shell_no_warning_for_bash_user(repo: TestRepo, temp_home: Temp
----- stderr -----
✓ Added shell extension & completions for bash @ ~/.bashrc
✓ Added shell extension & completions for zsh @ ~/.zshrc
- ↳ Skipped fish; ~/.config/fish/conf.d not found
+ ↳ Skipped fish; ~/.config/fish/functions not found
✓ Configured 2 shells
↳ Restart shell to activate shell integration
@@ -866,7 +1190,7 @@ fn test_configure_shell_no_warning_for_fish_install(repo: TestRepo, temp_home: T
----- stdout -----
----- stderr -----
- ✓ Created shell extension for fish @ ~/.config/fish/conf.d/wt.fish
+ ✓ Created shell extension for fish @ ~/.config/fish/functions/wt.fish
✓ Created completions for fish @ ~/.config/fish/completions/wt.fish
✓ Configured 1 shell
@@ -939,7 +1263,7 @@ fn test_configure_shell_no_warning_when_shell_unset(repo: TestRepo, temp_home: T
----- stderr -----
✓ Added shell extension & completions for bash @ ~/.bashrc
✓ Added shell extension & completions for zsh @ ~/.zshrc
- ↳ Skipped fish; ~/.config/fish/conf.d not found
+ ↳ Skipped fish; ~/.config/fish/functions not found
✓ Configured 2 shells
");
@@ -1075,6 +1399,7 @@ fn test_uninstall_shell_dry_run(repo: TestRepo, temp_home: TempDir) {
);
}
+/// Test dry-run with fish in legacy conf.d location (shows deprecated message)
#[rstest]
fn test_uninstall_shell_dry_run_fish(repo: TestRepo, temp_home: TempDir) {
// Create fish conf.d directory with wt.fish and completions
@@ -1117,6 +1442,49 @@ fn test_uninstall_shell_dry_run_fish(repo: TestRepo, temp_home: TempDir) {
);
}
+/// Test dry-run with fish in canonical functions/ location (shows normal message)
+#[rstest]
+fn test_uninstall_shell_dry_run_fish_canonical(repo: TestRepo, temp_home: TempDir) {
+ // Create fish functions directory with wt.fish (canonical location)
+ let functions = temp_home.path().join(".config/fish/functions");
+ fs::create_dir_all(&functions).unwrap();
+ let fish_config = functions.join("wt.fish");
+ // Write the exact wrapper content that install would create
+ let init =
+ worktrunk::shell::ShellInit::with_prefix(worktrunk::shell::Shell::Fish, "wt".to_string());
+ let wrapper_content = init.generate_fish_wrapper().unwrap();
+ fs::write(&fish_config, format!("{}\n", wrapper_content)).unwrap();
+
+ // Create completions file
+ let completions_d = temp_home.path().join(".config/fish/completions");
+ fs::create_dir_all(&completions_d).unwrap();
+ let completions_file = completions_d.join("wt.fish");
+ fs::write(&completions_file, "# fish completions").unwrap();
+
+ let settings = setup_home_snapshot_settings(&temp_home);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.configure_wt_cmd(&mut cmd);
+ set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("SHELL", "/bin/fish");
+ cmd.arg("config")
+ .arg("shell")
+ .arg("uninstall")
+ .arg("fish")
+ .arg("--dry-run")
+ .current_dir(repo.root_path());
+
+ assert_cmd_snapshot!(cmd);
+ });
+
+ // Verify files were NOT modified
+ assert!(fish_config.exists(), "Fish config should still exist");
+ assert!(
+ completions_file.exists(),
+ "Fish completions should still exist"
+ );
+}
+
#[rstest]
fn test_uninstall_shell_dry_run_multiple(repo: TestRepo, temp_home: TempDir) {
// Create multiple shell configs with wt integration
diff --git a/tests/integration_tests/shell_wrapper.rs b/tests/integration_tests/shell_wrapper.rs
index 400e1edeb..db4359672 100644
--- a/tests/integration_tests/shell_wrapper.rs
+++ b/tests/integration_tests/shell_wrapper.rs
@@ -43,6 +43,7 @@ use std::fs;
use std::path::PathBuf;
use std::process::Command;
use std::sync::LazyLock;
+use worktrunk::shell;
/// Regex for normalizing temporary directory paths in test snapshots
static TMPDIR_REGEX: LazyLock<regex::Regex> = LazyLock::new(|| {
@@ -1947,6 +1948,137 @@ approved-commands = ["echo 'bash background'"]
);
}
+ /// Test that fish wrapper shows clear error when wt binary is not available
+ ///
+ /// This tests the scenario where:
+ /// 1. User has shell integration installed (functions/wt.fish exists)
+ /// 2. But wt binary is not in PATH
+ /// 3. And WORKTRUNK_BIN is not set
+ ///
+ /// The fish function should show "wt: command not found" and exit 127.
+ /// This is fish-specific because bash/zsh have an outer guard that prevents
+ /// the function from being defined when wt isn't available.
+ #[rstest]
+ #[case("fish")]
+ fn test_fish_binary_not_found_clear_error(#[case] shell: &str, repo: TestRepo) {
+ let wrapper_script = generate_wrapper(&repo, shell);
+
+ // Script that clears PATH and does NOT set WORKTRUNK_BIN
+ // This simulates having the fish function installed but wt not available
+ let script = format!(
+ r#"
+ # Clear PATH to ensure wt is not found via PATH
+ set -x PATH /usr/bin /bin
+ # Explicitly unset WORKTRUNK_BIN to ensure it's not set
+ set -e WORKTRUNK_BIN
+ set -x CLICOLOR_FORCE 1
+ {}
+ wt --version
+ echo "exit_code: $status"
+ "#,
+ wrapper_script
+ );
+
+ let final_script = format!("begin\n{}\nend 2>&1", script);
+
+ let config_path = repo.test_config_path().to_string_lossy().to_string();
+ let env_vars = build_test_env_vars(&config_path);
+
+ let (combined, exit_code) =
+ exec_in_pty_interactive(shell, &final_script, repo.root_path(), &env_vars, &[]);
+
+ let output = ShellOutput {
+ combined,
+ exit_code,
+ };
+
+ // The function should show a clear error message
+ assert!(
+ output.combined.contains("wt: command not found"),
+ "Fish wrapper should show 'wt: command not found' when binary is missing.\nOutput:\n{}",
+ output.combined
+ );
+
+ // And return exit code 127 (standard "command not found" exit code)
+ assert!(
+ output.combined.contains("exit_code: 127"),
+ "Fish wrapper should return exit code 127 when binary is missing.\nOutput:\n{}",
+ output.combined
+ );
+ }
+
+ /// Test that fish WRAPPER (bootstrap) handles missing binary gracefully
+ ///
+ /// This tests the WRAPPER file (fish_wrapper.fish) that gets installed to
+ /// ~/.config/fish/functions/wt.fish. Unlike the full function (tested above),
+ /// the wrapper tries to SOURCE the full function from the binary at runtime.
+ ///
+ /// When wt isn't in PATH:
+ /// - `command wt config shell init fish` fails
+ /// - The wrapper should return 127, NOT infinite loop
+ ///
+ /// This is different from test_fish_binary_not_found_clear_error which tests
+ /// the FULL function (which has its own WORKTRUNK_BIN check).
+ #[rstest]
+ #[case("fish")]
+ fn test_fish_wrapper_binary_not_found_no_infinite_loop(#[case] shell: &str, repo: TestRepo) {
+ // Use the WRAPPER template (not the full function from generate_wrapper)
+ let init = shell::ShellInit::with_prefix(shell::Shell::Fish, "wt".to_string());
+ let wrapper_content = init.generate_fish_wrapper().unwrap();
+
+ // Script that clears PATH so wt isn't found, then calls wt
+ let script = format!(
+ r#"
+ # Clear PATH to ensure wt is not found
+ set -x PATH /usr/bin /bin
+ set -x CLICOLOR_FORCE 1
+ {}
+ wt --version
+ echo "exit_code: $status"
+ "#,
+ wrapper_content
+ );
+
+ let final_script = format!("begin\n{}\nend 2>&1", script);
+
+ let config_path = repo.test_config_path().to_string_lossy().to_string();
+ let env_vars = build_test_env_vars(&config_path);
+
+ let (combined, exit_code) =
+ exec_in_pty_interactive(shell, &final_script, repo.root_path(), &env_vars, &[]);
+
+ let output = ShellOutput {
+ combined,
+ exit_code,
+ };
+
+ // Should NOT show signs of infinite recursion (stack overflow, repeated function calls)
+ // One occurrence of "in function 'wt'" is normal (fish's error trace).
+ // Infinite recursion would show this MANY times.
+ let function_call_count = output.combined.matches("in function 'wt'").count();
+ assert!(
+ function_call_count <= 1,
+ "Fish wrapper should not infinite loop (found {} recursive calls).\nOutput:\n{}",
+ function_call_count,
+ output.combined
+ );
+
+ // Should return exit code 127 (command not found)
+ assert!(
+ output.combined.contains("exit_code: 127"),
+ "Fish wrapper should return exit code 127 when binary is missing.\nOutput:\n{}",
+ output.combined
+ );
+
+ // Should show fish's error message about unknown command
+ assert!(
+ output.combined.contains("Unknown command")
+ || output.combined.contains("command not found"),
+ "Fish wrapper should show error when binary is missing.\nOutput:\n{}",
+ output.combined
+ );
+ }
+
// ========================================================================
// Interrupt/Cleanup Tests
// ========================================================================
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_claude_available_plugin_not_installed.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_claude_available_plugin_not_installed.snap
index 98357aaf8..5138a0c09 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_claude_available_plugin_not_installed.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_claude_available_plugin_not_installed.snap
@@ -44,7 +44,7 @@ exit_code: 0
○ Skipped bash; ~/.bashrc not found
○ Skipped zsh; ~/.zshrc not found
-○ Skipped fish; ~/.config/fish/conf.d not found
+○ Skipped fish; ~/.config/fish/functions not found
OTHER
○ wt: [VERSION]
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_empty_project_config.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_empty_project_config.snap
index b84ac981b..8be9752fd 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_empty_project_config.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_empty_project_config.snap
@@ -44,7 +44,7 @@ exit_code: 0
○ Skipped bash; ~/.bashrc not found
○ Skipped zsh; ~/.zshrc not found
-○ Skipped fish; ~/.config/fish/conf.d not found
+○ Skipped fish; ~/.config/fish/functions not found
OTHER
○ wt: [VERSION]
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_full_command_not_found.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_full_command_not_found.snap
index 060048d59..7fc55c5e8 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_full_command_not_found.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_full_command_not_found.snap
@@ -49,7 +49,7 @@ exit_code: 0
○ Skipped bash; ~/.bashrc not found
○ Skipped zsh; ~/.zshrc not found
-○ Skipped fish; ~/.config/fish/conf.d not found
+○ Skipped fish; ~/.config/fish/functions not found
DIAGNOSTICS
↳ CI status requires GitHub or GitLab remote
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_full_not_configured.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_full_not_configured.snap
index 068efe67c..9fb483add 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_full_not_configured.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_full_not_configured.snap
@@ -45,7 +45,7 @@ exit_code: 0
○ Skipped bash; ~/.bashrc not found
○ Skipped zsh; ~/.zshrc not found
-○ Skipped fish; ~/.config/fish/conf.d not found
+○ Skipped fish; ~/.config/fish/functions not found
DIAGNOSTICS
↳ CI status requires GitHub or GitLab remote
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_github_remote.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_github_remote.snap
index c2b34c4f8..14bd91d42 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_github_remote.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_github_remote.snap
@@ -44,7 +44,7 @@ exit_code: 0
○ Skipped bash; ~/.bashrc not found
○ Skipped zsh; ~/.zshrc not found
-○ Skipped fish; ~/.config/fish/conf.d not found
+○ Skipped fish; ~/.config/fish/functions not found
OTHER
○ wt: [VERSION]
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_gitlab_remote.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_gitlab_remote.snap
index c2b34c4f8..14bd91d42 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_gitlab_remote.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_gitlab_remote.snap
@@ -44,7 +44,7 @@ exit_code: 0
○ Skipped bash; ~/.bashrc not found
○ Skipped zsh; ~/.zshrc not found
-○ Skipped fish; ~/.config/fish/conf.d not found
+○ Skipped fish; ~/.config/fish/functions not found
OTHER
○ wt: [VERSION]
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_invalid_project_toml.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_invalid_project_toml.snap
index fe232fbd3..fb55e68be 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_invalid_project_toml.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_invalid_project_toml.snap
@@ -50,7 +50,7 @@ exit_code: 0
○ Skipped bash; ~/.bashrc not found
○ Skipped zsh; ~/.zshrc not found
-○ Skipped fish; ~/.config/fish/conf.d not found
+○ Skipped fish; ~/.config/fish/functions not found
OTHER
○ wt: [VERSION]
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_invalid_user_toml.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_invalid_user_toml.snap
index 0ce2dbc7e..1d557724e 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_invalid_user_toml.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_invalid_user_toml.snap
@@ -50,7 +50,7 @@ exit_code: 0
○ Skipped bash; ~/.bashrc not found
○ Skipped zsh; ~/.zshrc not found
-○ Skipped fish; ~/.config/fish/conf.d not found
+○ Skipped fish; ~/.config/fish/functions not found
OTHER
○ wt: [VERSION]
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_no_project_config.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_no_project_config.snap
index c2b34c4f8..14bd91d42 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_no_project_config.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_no_project_config.snap
@@ -44,7 +44,7 @@ exit_code: 0
○ Skipped bash; ~/.bashrc not found
○ Skipped zsh; ~/.zshrc not found
-○ Skipped fish; ~/.config/fish/conf.d not found
+○ Skipped fish; ~/.config/fish/functions not found
OTHER
○ wt: [VERSION]
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_no_user_config.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_no_user_config.snap
index a6bbdf6d2..7446c468c 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_no_user_config.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_no_user_config.snap
@@ -44,7 +44,7 @@ exit_code: 0
○ Skipped bash; ~/.bashrc not found
○ Skipped zsh; ~/.zshrc not found
-○ Skipped fish; ~/.config/fish/conf.d not found
+○ Skipped fish; ~/.config/fish/functions not found
OTHER
○ wt: [VERSION]
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_outside_git_repo.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_outside_git_repo.snap
index 940c35fb2..655e3697f 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_outside_git_repo.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_outside_git_repo.snap
@@ -36,7 +36,7 @@ exit_code: 0
○ Skipped bash; ~/.bashrc not found
○ Skipped zsh; ~/.zshrc not found
-○ Skipped fish; ~/.config/fish/conf.d not found
+○ Skipped fish; ~/.config/fish/functions not found
OTHER
○ wt: [VERSION]
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_partial_shell_config_shows_hint.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_partial_shell_config_shows_hint.snap
index c9f5ff389..e44a33d63 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_partial_shell_config_shows_hint.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_partial_shell_config_shows_hint.snap
@@ -43,12 +43,12 @@ exit_code: 0
▲ Shell integration not active
  Binary invoked as: [PROJECT_ROOT]/target/debug/wt
-↳ Not configured shell extension & completions for bash @ ~/.bashrc
+↳ Not configured shell extension & completions for bash
○ Already configured shell extension & completions for zsh @ ~/.zshrc:2
  if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)"; fi
-○ Skipped fish; ~/.config/fish/conf.d not found
+○ Skipped fish; ~/.config/fish/functions not found
-↳ To enable shell integration, run wt config shell install
+↳ To configure, run wt config shell install
OTHER
○ wt: [VERSION]
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_plugin_installed.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_plugin_installed.snap
index 55809a804..01823061c 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_plugin_installed.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_plugin_installed.snap
@@ -44,7 +44,7 @@ exit_code: 0
○ Skipped bash; ~/.bashrc not found
○ Skipped zsh; ~/.zshrc not found
-○ Skipped fish; ~/.config/fish/conf.d not found
+○ Skipped fish; ~/.config/fish/functions not found
OTHER
○ wt: [VERSION]
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_shell_integration_active.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_shell_integration_active.snap
index f0c928ee3..9efe1705f 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_shell_integration_active.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_shell_integration_active.snap
@@ -44,7 +44,7 @@ exit_code: 0
○ Skipped bash; ~/.bashrc not found
○ Skipped zsh; ~/.zshrc not found
-○ Skipped fish; ~/.config/fish/conf.d not found
+○ Skipped fish; ~/.config/fish/functions not found
OTHER
○ wt: [VERSION]
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_unmatched_candidate_warning.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_unmatched_candidate_warning.snap
index 9a66b5237..053bbcf2c 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_unmatched_candidate_warning.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_unmatched_candidate_warning.snap
@@ -43,15 +43,14 @@ exit_code: 0
▲ Shell integration not active
  Binary invoked as: [PROJECT_ROOT]/target/debug/wt
-↳ Not configured shell extension & completions for bash @ ~/.bashrc
+↳ Not configured shell extension & completions for bash
○ Skipped zsh; ~/.zshrc not found
-○ Skipped fish; ~/.config/fish/conf.d not found
+○ Skipped fish; ~/.config/fish/functions not found
-↳ To enable shell integration, run wt config shell install
+↳ To configure, run wt config shell install
▲ Found wt in ~/.bashrc:3 but not detected as integration:
  alias wt="git worktree"
-
-↳ If this is shell integration, report a false negative: https://github.com/max-sixty/worktrunk/issues/new?title=Shell%20integration%20detection%20false%20negative&body=Shell%20integration%20not%20detected%20despite%20config%20containing%20%60wt%60.%0A%0A%2A%2AUnmatched%20lines%3A%2A%2A%0A%60%60%60%0Aalias%20wt%3D%22git%20worktree%22%0A%60%60%60%0A%0A%2A%2AExpected%20behavior%3A%2A%2A%20These%20lines%20should%20be%20detected%20as%20shell%20integration.
+↳ If `alias wt="git worktree"` is shell integration, report a false negative: https://github.com/max-sixty/worktrunk/issues/new?title=Shell%20integration%20detection%20false%20negative&body=Shell%20integration%20not%20detected%20despite%20config%20containing%20%60wt%60.%0A%0A%2A%2AUnmatched%20lines%3A%2A%2A%0A%60%60%60%0Aalias%20wt%3D%22git%20worktree%22%0A%60%60%60%0A%0A%2A%2AExpected%20behavior%3A%2A%2A%20These%20lines%20should%20be%20detected%20as%20shell%20integration.
OTHER
○ wt: [VERSION]
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_warns_unknown_project_keys.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_warns_unknown_project_keys.snap
index 07f9f5b0e..52f59eb4d 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_warns_unknown_project_keys.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_warns_unknown_project_keys.snap
@@ -46,7 +46,7 @@ exit_code: 0
○ Skipped bash; ~/.bashrc not found
○ Skipped zsh; ~/.zshrc not found
-○ Skipped fish; ~/.config/fish/conf.d not found
+○ Skipped fish; ~/.config/fish/functions not found
OTHER
○ wt: [VERSION]
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_warns_unknown_user_keys.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_warns_unknown_user_keys.snap
index 2c003e786..867493d7a 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_warns_unknown_user_keys.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_warns_unknown_user_keys.snap
@@ -48,7 +48,7 @@ exit_code: 0
○ Skipped bash; ~/.bashrc not found
○ Skipped zsh; ~/.zshrc not found
-○ Skipped fish; ~/.config/fish/conf.d not found
+○ Skipped fish; ~/.config/fish/functions not found
OTHER
○ wt: [VERSION]
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_whitespace_only_project_config.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_whitespace_only_project_config.snap
index b84ac981b..8be9752fd 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_whitespace_only_project_config.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_whitespace_only_project_config.snap
@@ -44,7 +44,7 @@ exit_code: 0
○ Skipped bash; ~/.bashrc not found
○ Skipped zsh; ~/.zshrc not found
-○ Skipped fish; ~/.config/fish/conf.d not found
+○ Skipped fish; ~/.config/fish/functions not found
OTHER
○ wt: [VERSION]
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_with_project_config.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_with_project_config.snap
index d55ba5375..5a0786779 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_with_project_config.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_with_project_config.snap
@@ -50,7 +50,7 @@ exit_code: 0
○ Skipped bash; ~/.bashrc not found
○ Skipped zsh; ~/.zshrc not found
-○ Skipped fish; ~/.config/fish/conf.d not found
+○ Skipped fish; ~/.config/fish/functions not found
OTHER
○ wt: [VERSION]
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_zsh_compinit_correct_order.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_zsh_compinit_correct_order.snap
index 7d3b41b40..ba7370962 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_zsh_compinit_correct_order.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_zsh_compinit_correct_order.snap
@@ -46,7 +46,7 @@ exit_code: 0
○ Already configured shell extension & completions for zsh @ ~/.zshrc:5
  if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)"; fi
○ Skipped bash; ~/.bashrc not found
-○ Skipped fish; ~/.config/fish/conf.d not found
+○ Skipped fish; ~/.config/fish/functions not found
OTHER
○ wt: [VERSION]
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_zsh_compinit_warning.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_zsh_compinit_warning.snap
index 03475e7b3..2221994cb 100644
--- a/tests/snapshots/integration__integration_tests__config_show__config_show_zsh_compinit_warning.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_zsh_compinit_warning.snap
@@ -48,7 +48,7 @@ exit_code: 0
▲ Completions won't work; add to ~/.zshrc before the wt line:
  autoload -Uz compinit && compinit
○ Skipped bash; ~/.bashrc not found
-○ Skipped fish; ~/.config/fish/conf.d not found
+○ Skipped fish; ~/.config/fish/functions not found
OTHER
○ wt: [VERSION]
diff --git a/tests/snapshots/integration__integration_tests__configure_shell__config_show_detects_fish_legacy_conf_d.snap b/tests/snapshots/integration__integration_tests__configure_shell__config_show_detects_fish_legacy_conf_d.snap
new file mode 100644
index 000000000..89381bc4d
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__configure_shell__config_show_detects_fish_legacy_conf_d.snap
@@ -0,0 +1,55 @@
+---
+source: tests/integration_tests/configure_shell.rs
+info:
+ program: wt
+ args:
+ - config
+ - show
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SHELL: /bin/fish
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+USER CONFIG ~/.config/worktrunk/config.toml
+↳ Not found; to create one, run wt config create
+
+PROJECT CONFIG _REPO_/.config/wt.toml
+↳ Not found
+
+SHELL INTEGRATION
+▲ Shell integration not active
+  Binary invoked as: [PROJECT_ROOT]/target/debug/wt
+
+○ Skipped bash; ~/.bashrc not found
+○ Skipped zsh; ~/.zshrc not found
+○ Fish integration found in deprecated location @ ~/.config/fish/conf.d/wt.fish
+↳ To migrate to ~/.config/fish/functions/wt.fish, run wt config shell install fish
+
+OTHER
+○ wt: [VERSION]
+○ git: [VERSION]
+↳ Claude Code plugin not installed (claude not found)
+○ Hyperlinks: inactive
diff --git a/tests/snapshots/integration__integration_tests__configure_shell__config_show_fish_legacy_with_functions_dir.snap b/tests/snapshots/integration__integration_tests__configure_shell__config_show_fish_legacy_with_functions_dir.snap
new file mode 100644
index 000000000..2c0717984
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__configure_shell__config_show_fish_legacy_with_functions_dir.snap
@@ -0,0 +1,55 @@
+---
+source: tests/integration_tests/configure_shell.rs
+info:
+ program: wt
+ args:
+ - config
+ - show
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SHELL: /bin/fish
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+USER CONFIG ~/.config/worktrunk/config.toml
+↳ Not found; to create one, run wt config create
+
+PROJECT CONFIG _REPO_/.config/wt.toml
+↳ Not found
+
+SHELL INTEGRATION
+▲ Shell integration not active
+  Binary invoked as: [PROJECT_ROOT]/target/debug/wt
+
+○ Fish integration found in deprecated location @ ~/.config/fish/conf.d/wt.fish
+↳ To migrate to ~/.config/fish/functions/wt.fish, run wt config shell install fish
+○ Skipped bash; ~/.bashrc not found
+○ Skipped zsh; ~/.zshrc not found
+
+OTHER
+○ wt: [VERSION]
+○ git: [VERSION]
+↳ Claude Code plugin not installed (claude not found)
+○ Hyperlinks: inactive
diff --git a/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_fish_all_already_configured.snap b/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_fish_all_already_configured.snap
index 390ead27f..6ff1d4590 100644
--- a/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_fish_all_already_configured.snap
+++ b/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_fish_all_already_configured.snap
@@ -11,7 +11,7 @@ info:
env:
APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
- COLUMNS: "150"
+ COLUMNS: "500"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
@@ -25,6 +25,7 @@ info:
RUST_LOG: warn
SHELL: /bin/fish
SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
USERPROFILE: "[TEST_HOME]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
@@ -35,7 +36,7 @@ exit_code: 0
----- stdout -----
----- stderr -----
-○ Already configured shell extension for fish @ ~/.config/fish/conf.d/wt.fish
+○ Already configured shell extension for fish @ ~/.config/fish/functions/wt.fish
✓ Created completions for fish @ ~/.config/fish/completions/wt.fish
✓ Configured 1 shell
diff --git a/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_fish_dry_run.snap b/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_fish_dry_run.snap
new file mode 100644
index 000000000..5157f08b9
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_fish_dry_run.snap
@@ -0,0 +1,58 @@
+---
+source: tests/integration_tests/configure_shell.rs
+info:
+ program: wt
+ args:
+ - config
+ - shell
+ - install
+ - fish
+ - "--dry-run"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SHELL: /bin/fish
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ Will create shell extension for fish @ ~/.config/fish/functions/wt.fish
+  # worktrunk shell integration for fish
+  # Sources full integration from binary on first use.
+  # Docs: https://worktrunk.dev/docs/shell-integration
+  # Check: wt config show | Uninstall: wt config shell uninstall
+  
+  function wt
+   command wt config shell init fish | source
+   # Check both command exit code ($pipestatus[1]) and source exit code ($pipestatus[2])
+   # If source fails, the function isn't replaced and we'd infinite-loop calling ourselves
+   set -l wt_status $pipestatus[1]
+   set -l source_status $pipestatus[2]
+   test $wt_status -eq 0; or return $wt_status
+   test $source_status -eq 0; or return $source_status
+   wt $argv
+  end
+
+○ Will create completions for fish @ ~/.config/fish/completions/wt.fish
+  # worktrunk completions for fish
+  complete --keep-order --exclusive --command wt --arguments "(test -n /"/$WORKTRUNK_BIN/"; or set -l WORKTRUNK_BIN (type -P wt 2>/dev/null); and COMPLETE=fish /$WORKTRUNK_BIN -- (commandline --current-process --tokenize --cut-at-cursor) (commandline --current-token))"
diff --git a/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_fish_dry_run_does_not_delete_legacy.snap b/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_fish_dry_run_does_not_delete_legacy.snap
new file mode 100644
index 000000000..8ed60ab14
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_fish_dry_run_does_not_delete_legacy.snap
@@ -0,0 +1,41 @@
+---
+source: tests/integration_tests/configure_shell.rs
+info:
+ program: wt
+ args:
+ - config
+ - shell
+ - install
+ - fish
+ - "--dry-run"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SHELL: /bin/fish
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ Will add completions for fish @ ~/.config/fish/completions/wt.fish
+  # worktrunk completions for fish
+  complete --keep-order --exclusive --command wt --arguments "(test -n /"/$WORKTRUNK_BIN/"; or set -l WORKTRUNK_BIN (type -P wt 2>/dev/null); and COMPLETE=fish /$WORKTRUNK_BIN -- (commandline --current-process --tokenize --cut-at-cursor) (commandline --current-token))"
diff --git a/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_fish_legacy_cleanup_even_when_already_exists.snap b/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_fish_legacy_cleanup_even_when_already_exists.snap
new file mode 100644
index 000000000..8fbe6e645
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_fish_legacy_cleanup_even_when_already_exists.snap
@@ -0,0 +1,43 @@
+---
+source: tests/integration_tests/configure_shell.rs
+info:
+ program: wt
+ args:
+ - config
+ - shell
+ - install
+ - fish
+ - "--yes"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SHELL: /bin/fish
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ Already configured shell extension for fish @ ~/.config/fish/functions/wt.fish
+✓ Created completions for fish @ ~/.config/fish/completions/wt.fish
+○ Removed ~/.config/fish/conf.d/wt.fish (deprecated; now using ~/.config/fish/functions/wt.fish)
+
+✓ Configured 1 shell
diff --git a/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_fish_legacy_conf_d_cleanup.snap b/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_fish_legacy_conf_d_cleanup.snap
new file mode 100644
index 000000000..31b674f0f
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_fish_legacy_conf_d_cleanup.snap
@@ -0,0 +1,44 @@
+---
+source: tests/integration_tests/configure_shell.rs
+info:
+ program: wt
+ args:
+ - config
+ - shell
+ - install
+ - fish
+ - "--yes"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SHELL: /bin/fish
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+✓ Created shell extension for fish @ ~/.config/fish/functions/wt.fish
+✓ Created completions for fish @ ~/.config/fish/completions/wt.fish
+○ Removed ~/.config/fish/conf.d/wt.fish (deprecated; now using ~/.config/fish/functions/wt.fish)
+
+✓ Configured 1 shell
+↳ Restart shell to activate shell integration
diff --git a/tests/snapshots/integration__integration_tests__configure_shell__pty_tests__install_preview_with_gutter.snap b/tests/snapshots/integration__integration_tests__configure_shell__pty_tests__install_preview_with_gutter.snap
index de660625a..ea53af0fc 100644
--- a/tests/snapshots/integration__integration_tests__configure_shell__pty_tests__install_preview_with_gutter.snap
+++ b/tests/snapshots/integration__integration_tests__configure_shell__pty_tests__install_preview_with_gutter.snap
@@ -5,7 +5,7 @@ expression: normalized
❯ Install shell integration? [y/N/?]
✓ Added shell extension & completions for zsh @ ~/.zshrc
↳ Skipped bash; ~/.bashrc not found
-↳ Skipped fish; ~/.config/fish/conf.d not found
+↳ Skipped fish; ~/.config/fish/functions not found
✓ Configured 1 shell
▲ Completions require compinit; add to ~/.zshrc before the wt line:
autoload -Uz compinit && compinit
diff --git a/tests/snapshots/integration__integration_tests__configure_shell__uninstall_shell_dry_run_fish.snap b/tests/snapshots/integration__integration_tests__configure_shell__uninstall_shell_dry_run_fish.snap
index b08b4ca69..19f683f26 100644
--- a/tests/snapshots/integration__integration_tests__configure_shell__uninstall_shell_dry_run_fish.snap
+++ b/tests/snapshots/integration__integration_tests__configure_shell__uninstall_shell_dry_run_fish.snap
@@ -36,5 +36,5 @@ exit_code: 0
----- stdout -----
----- stderr -----
-○ Will remove shell extension for fish @ ~/.config/fish/conf.d/wt.fish
+○ Will remove ~/.config/fish/conf.d/wt.fish (deprecated; now using ~/.config/fish/functions/wt.fish)
○ Will remove completions for fish @ ~/.config/fish/completions/wt.fish
diff --git a/tests/snapshots/integration__integration_tests__configure_shell__uninstall_shell_dry_run_fish_canonical.snap b/tests/snapshots/integration__integration_tests__configure_shell__uninstall_shell_dry_run_fish_canonical.snap
new file mode 100644
index 000000000..5b4996335
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__configure_shell__uninstall_shell_dry_run_fish_canonical.snap
@@ -0,0 +1,40 @@
+---
+source: tests/integration_tests/configure_shell.rs
+info:
+ program: wt
+ args:
+ - config
+ - shell
+ - uninstall
+ - fish
+ - "--dry-run"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SHELL: /bin/fish
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+○ Will remove shell extension for fish @ ~/.config/fish/functions/wt.fish
+○ Will remove completions for fish @ ~/.config/fish/completions/wt.fish
diff --git a/tests/snapshots/integration__integration_tests__configure_shell__uninstall_shell_fish_legacy_conf_d_cleanup.snap b/tests/snapshots/integration__integration_tests__configure_shell__uninstall_shell_fish_legacy_conf_d_cleanup.snap
new file mode 100644
index 000000000..21f7127ea
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__configure_shell__uninstall_shell_fish_legacy_conf_d_cleanup.snap
@@ -0,0 +1,44 @@
+---
+source: tests/integration_tests/configure_shell.rs
+info:
+ program: wt
+ args:
+ - config
+ - shell
+ - uninstall
+ - fish
+ - "--yes"
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ GIT_TERMINAL_PROMPT: "0"
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ PATH: "[PATH]"
+ RUST_LOG: warn
+ SHELL: /bin/fish
+ SOURCE_DATE_EPOCH: "1735776000"
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+
+----- stderr -----
+✓ Removed shell extension for fish @ ~/.config/fish/functions/wt.fish
+✓ Removed shell extension for fish @ ~/.config/fish/conf.d/wt.fish
+✓ Removed completions for fish @ ~/.config/fish/completions/wt.fish
+
+✓ Removed integration from 1 shell
+↳ Restart shell to complete uninstall
diff --git a/tests/snapshots/integration__integration_tests__init__init_fish.snap b/tests/snapshots/integration__integration_tests__init__init_fish.snap
index 6669cf7d2..c604c28a0 100644
--- a/tests/snapshots/integration__integration_tests__init__init_fish.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_fish.snap
@@ -10,7 +10,7 @@ info:
env:
APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
- COLUMNS: "150"
+ COLUMNS: "500"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
@@ -33,49 +33,52 @@ success: true
exit_code: 0
----- stdout -----
# worktrunk shell integration for fish
+#
+# This is the full function definition, output by `wt config shell init fish`.
+# It's sourced at runtime by the wrapper in ~/.config/fish/functions/wt.fish.
-# Only initialize if wt is available (in PATH or via WORKTRUNK_BIN)
-if type -q wt; or test -n "$WORKTRUNK_BIN"
+# Override wt command with file-based directive passing.
+# Creates a temp file, passes path via WORKTRUNK_DIRECTIVE_FILE, evals it after.
+# WORKTRUNK_BIN can override the binary path (for testing dev builds).
+#
+# Note: We use `eval (cat ... | string collect)` instead of `source` because:
+# 1. fish's `source` doesn't propagate exit codes to the parent function
+# 2. `eval (cat ...)` without `string collect` splits on newlines, breaking multiline directives
+# With `string collect`, we get proper exit code propagation for cd and other directives.
+function wt
+ set -l use_source false
+ set -l args
- # Override wt command with file-based directive passing.
- # Creates a temp file, passes path via WORKTRUNK_DIRECTIVE_FILE, evals it after.
- # WORKTRUNK_BIN can override the binary path (for testing dev builds).
- #
- # Note: We use `eval (cat ... | string collect)` instead of `source` because:
- # 1. fish's `source` doesn't propagate `exit` to the parent function
- # 2. `eval (cat ...)` without `string collect` splits on newlines, breaking multiline directives
- # With `string collect`, `exit 42` properly exits the function with code 42.
- function wt
- set -l use_source false
- set -l args
-
- for arg in $argv
- if test "$arg" = "--source"; set use_source true; else; set -a args $arg; end
- end
+ for arg in $argv
+ if test "$arg" = "--source"; set use_source true; else; set -a args $arg; end
+ end
- test -n "$WORKTRUNK_BIN"; or set -l WORKTRUNK_BIN (type -P wt)
- set -l directive_file (mktemp)
+ test -n "$WORKTRUNK_BIN"; or set -l WORKTRUNK_BIN (type -P wt 2>/dev/null)
+ if test -z "$WORKTRUNK_BIN"
+ echo "wt: command not found" >&2
+ return 127
+ end
+ set -l directive_file (mktemp)
- # --source: use cargo run (builds from source)
- if test $use_source = true
- WORKTRUNK_DIRECTIVE_FILE=$directive_file cargo run --bin wt --quiet -- $args
- else
- WORKTRUNK_DIRECTIVE_FILE=$directive_file command $WORKTRUNK_BIN $args
- end
- set -l exit_code $status
+ # --source: use cargo run (builds from source)
+ if test $use_source = true
+ WORKTRUNK_DIRECTIVE_FILE=$directive_file cargo run --bin wt --quiet -- $args
+ else
+ WORKTRUNK_DIRECTIVE_FILE=$directive_file command $WORKTRUNK_BIN $args
+ end
+ set -l exit_code $status
- if test -s "$directive_file"
- eval (cat "$directive_file" | string collect)
- if test $exit_code -eq 0
- set exit_code $status
- end
+ if test -s "$directive_file"
+ eval (cat "$directive_file" | string collect)
+ if test $exit_code -eq 0
+ set exit_code $status
end
-
- rm -f "$directive_file"
- return $exit_code
end
- # Completions are in ~/.config/fish/completions/wt.fish (installed by `wt config shell install`)
+ rm -f "$directive_file"
+ return $exit_code
end
+# Completions are in ~/.config/fish/completions/wt.fish (installed by `wt config shell install`)
+
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_accept.snap b/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_accept.snap
index 305eabe9c..e24c32c47 100644
--- a/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_accept.snap
+++ b/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_accept.snap
@@ -11,7 +11,7 @@ y
❯ Install shell integration? [y/N/?]
✓ Added shell extension & completions for bash @ ~/.bashrc
↳ Skipped zsh; ~/.zshrc not found
-↳ Skipped fish; ~/.config/fish/conf.d not found
+↳ Skipped fish; ~/.config/fish/functions not found
✓ Configured 1 shell
↳ Restart shell to activate shell integration