Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Simplify shell integration API by removing prefix variants
Maximilian Roos1cf72dcef89e
diff --git a/src/commands/config.rs b/src/commands/config.rsindex b174513a9..161d7a208 100644--- a/src/commands/config.rs+++ b/src/commands/config.rs@@ -400,7 +400,7 @@ fn render_shell_status(out: &mut String) -> anyhow::Result<()> {// For fish, check completions file separatelyif matches!(shell, Shell::Fish)- && let Ok(completion_path) = shell.completion_path_with_prefix(&cmd)+ && let Ok(completion_path) = shell.completion_path(&cmd){let completion_display = format_path_for_display(&completion_path);if completion_path.exists() {diff --git a/src/commands/configure_shell.rs b/src/commands/configure_shell.rsindex 5b987d078..24a97e2d0 100644--- a/src/commands/configure_shell.rs+++ b/src/commands/configure_shell.rs@@ -228,7 +228,7 @@ pub fn scan_shell_configs(for shell in shells {let paths = shell- .config_paths_with_prefix(cmd)+ .config_paths(cmd).map_err(|e| format!("Failed to get config paths for {}: {}", shell, e))?;// Find the first existing config file@@ -300,7 +300,7 @@ fn configure_shell_file(cmd: &str,) -> Result<Option<ConfigureResult>, String> {// The line we write to the config file (also used for display)- let config_line = shell.config_line_with_prefix(cmd);+ let config_line = shell.config_line(cmd);// For Fish, we write to a separate conf.d/ fileif matches!(shell, Shell::Fish) {@@ -607,7 +607,7 @@ pub fn process_shell_completions(}let completion_path = shell- .completion_path_with_prefix(cmd)+ .completion_path(cmd).map_err(|e| format!("Failed to get completion path for {}: {}", shell, e))?;// Check if completions already exist with correct content@@ -699,7 +699,7 @@ fn scan_for_uninstall(for &shell in &shells {let paths = shell- .config_paths_with_prefix(cmd)+ .config_paths(cmd).map_err(|e| format!("Failed to get config paths for {}: {}", shell, e))?;// For Fish, delete entire {cmd}.fish file@@ -767,7 +767,7 @@ fn scan_for_uninstall(}let completion_path = shell- .completion_path_with_prefix(cmd)+ .completion_path(cmd).map_err(|e| format!("Failed to get completion path for {}: {}", shell, e))?;if completion_path.exists() {diff --git a/src/commands/list/render.rs b/src/commands/list/render.rsindex d1c4d4590..745177d02 100644--- a/src/commands/list/render.rs+++ b/src/commands/list/render.rs@@ -17,24 +17,20 @@ use worktrunk::git::LineDiff;impl DiffDisplayConfig {/// Format diff values with fixed-width alignment for tabular display.///- /// Numbers are right-aligned within their allocated digit width.+ /// Numbers are right-aligned within a 3-digit column width./// Returns empty spaces if both values are zero (unless `always_show_zeros` is set).- ///- /// # Arguments- /// * `positive` - The positive (added) value- /// * `negative` - The negative (deleted) value- /// * `digits` - Number of digits to allocate for each column (e.g., 3 for values up to 999)#[cfg(unix)] // Only used by select command which is unix-only- pub fn format_aligned(&self, positive: usize, negative: usize, digits: usize) -> String {+ pub fn format_aligned(&self, positive: usize, negative: usize) -> String {use super::layout::DiffColumnConfig;- let positive_width = 1 + digits; // symbol + digits- let negative_width = 1 + digits;+ const DIGITS: usize = 3;+ let positive_width = 1 + DIGITS; // symbol + digits+ let negative_width = 1 + DIGITS;let total_width = positive_width + 1 + negative_width; // with separatorlet config = DiffColumnConfig {- positive_digits: digits,- negative_digits: digits,+ positive_digits: DIGITS,+ negative_digits: DIGITS,total_width,display: *self,};@@ -745,10 +741,10 @@ mod tests {always_show_zeros: false,};- // Test various values with 3-digit columns- let result1 = config.format_aligned(310, 112, 3);- let result2 = config.format_aligned(54, 63, 3);- let result3 = config.format_aligned(9, 3, 3);+ // Test various values+ let result1 = config.format_aligned(310, 112);+ let result2 = config.format_aligned(54, 63);+ let result3 = config.format_aligned(9, 3);// All should have the same width (3 + 1 + 3 + 1 + 3 = 9 chars for "+NNN -NNN")let clean1 = result1.ansi_strip().into_owned();@@ -792,7 +788,7 @@ mod tests {};// Insertions only- let ins_only = config.format_aligned(447, 0, 3);+ let ins_only = config.format_aligned(447, 0);let clean_ins = ins_only.ansi_strip().into_owned();assert!(clean_ins.contains("+447"),@@ -801,7 +797,7 @@ mod tests {);// Deletions only- let del_only = config.format_aligned(0, 5, 3);+ let del_only = config.format_aligned(0, 5);let clean_del = del_only.ansi_strip().into_owned();assert!(clean_del.contains("-5"),diff --git a/src/commands/select.rs b/src/commands/select.rsindex 8c67d583e..fbadb30a6 100644--- a/src/commands/select.rs+++ b/src/commands/select.rs@@ -783,8 +783,7 @@ wherenegative_style: DELETION,always_show_zeros: false,};- // 3 digits handles values up to 999; overflow uses K notation- let stat_str = format!(" {}", diff_config.format_aligned(insertions, deletions, 3));+ let stat_str = format!(" {}", diff_config.format_aligned(insertions, deletions));format!("{}{} {dim_style}{:>width$}{reset}{}",diff --git a/src/shell.rs b/src/shell.rsindex f05f73ab7..fb4559e20 100644--- a/src/shell.rs+++ b/src/shell.rs@@ -89,15 +89,11 @@ pub enum Shell {}impl Shell {- /// Returns the standard config file paths for this 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`)./// Returns paths in order of preference. The first existing file should be used.- pub fn config_paths(&self) -> Result<Vec<PathBuf>, std::io::Error> {- self.config_paths_with_prefix("wt")- }-- /// Returns config paths with custom prefix (affects fish conf.d filename)- pub fn config_paths_with_prefix(&self, cmd: &str) -> Result<Vec<PathBuf>, std::io::Error> {+ pub fn config_paths(&self, cmd: &str) -> Result<Vec<PathBuf>, std::io::Error> {let home = home_dir_required()?;Ok(match self {@@ -125,18 +121,15 @@ impl Shell {})}- /// Returns the path to the native completion directory for this shell+ /// 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`).////// Note: Bash and Zsh use inline lazy completions in the init script.- /// Only Fish uses a separate completion file at ~/.config/fish/completions/wt.fish+ /// Only Fish uses a separate completion file at ~/.config/fish/completions//// (installed by `wt config shell install`) that uses $WORKTRUNK_BIN to bypass/// the shell function wrapper.- pub fn completion_path(&self) -> Result<PathBuf, std::io::Error> {- self.completion_path_with_prefix("wt")- }-- /// Returns completion path with custom prefix (affects fish completion filename)- pub fn completion_path_with_prefix(&self, cmd: &str) -> Result<PathBuf, std::io::Error> {+ pub fn completion_path(&self, cmd: &str) -> Result<PathBuf, std::io::Error> {let home = home_dir_required()?;// Use etcetera for XDG-compliant paths when available@@ -175,38 +168,30 @@ impl Shell {})}- /// Returns the line to add to the config file for shell integration+ /// Returns the line to add to the config file for shell integration.///+ /// The `cmd` parameter specifies the command name (e.g., `wt` or `git-wt`)./// All shells use a conditional wrapper to avoid errors when the command doesn't exist.- pub fn config_line(&self) -> String {- self.config_line_with_prefix("wt")- }-- /// Returns the line to add to the config file for shell integration with custom prefix- pub fn config_line_with_prefix(&self, cmd: &str) -> String {- // For non-default prefixes, include --cmd in the init command- let prefix_arg = if cmd == "wt" {- String::new()- } else {- format!(" --cmd={}", cmd)- };-+ ///+ /// Note: The generated line does not include `--cmd` because `binary_name()` already+ /// detects the command name from argv\[0\] at runtime.+ pub fn config_line(&self, cmd: &str) -> String {match self {Self::Bash | Self::Zsh => {format!(- "if command -v {cmd} >/dev/null 2>&1; then eval \"$(command {cmd} config shell init {}{prefix_arg})\"; fi",+ "if command -v {cmd} >/dev/null 2>&1; then eval \"$(command {cmd} config shell init {})\"; fi",self)}Self::Fish => {format!(- "if type -q {cmd}; command {cmd} config shell init {}{prefix_arg} | source; end",+ "if type -q {cmd}; command {cmd} config shell init {} | source; end",self)}Self::PowerShell => {format!(- "if (Get-Command {cmd} -ErrorAction SilentlyContinue) {{ Invoke-Expression (& {cmd} config shell init powershell{prefix_arg}) }}",+ "if (Get-Command {cmd} -ErrorAction SilentlyContinue) {{ Invoke-Expression (& {cmd} config shell init powershell) }}",)}}@@ -473,7 +458,7 @@ mod tests {#[test]fn test_shell_config_line_bash() {- let line = Shell::Bash.config_line();+ let line = Shell::Bash.config_line("wt");assert!(line.contains("eval"));assert!(line.contains("wt config shell init bash"));assert!(line.contains("command -v wt"));@@ -481,14 +466,14 @@ mod tests {#[test]fn test_shell_config_line_zsh() {- let line = Shell::Zsh.config_line();+ let line = Shell::Zsh.config_line("wt");assert!(line.contains("eval"));assert!(line.contains("wt config shell init zsh"));}#[test]fn test_shell_config_line_fish() {- let line = Shell::Fish.config_line();+ let line = Shell::Fish.config_line("wt");assert!(line.contains("type -q wt"));assert!(line.contains("wt config shell init fish"));assert!(line.contains("source"));@@ -496,7 +481,7 @@ mod tests {#[test]fn test_shell_config_line_powershell() {- let line = Shell::PowerShell.config_line();+ let line = Shell::PowerShell.config_line("wt");assert!(line.contains("Invoke-Expression"));assert!(line.contains("wt config shell init powershell"));}@@ -509,7 +494,7 @@ mod tests {let prefix = "git-wt";// Bash/Zsh- let bash_line = Shell::Bash.config_line_with_prefix(prefix);+ let bash_line = Shell::Bash.config_line(prefix);assert!(bash_line.contains("command -v git-wt"),"bash should check for git-wt"@@ -520,7 +505,7 @@ mod tests {);// Fish- let fish_line = Shell::Fish.config_line_with_prefix(prefix);+ let fish_line = Shell::Fish.config_line(prefix);assert!(fish_line.contains("type -q git-wt"),"fish should check for git-wt"@@ -531,7 +516,7 @@ mod tests {);// PowerShell- let ps_line = Shell::PowerShell.config_line_with_prefix(prefix);+ let ps_line = Shell::PowerShell.config_line(prefix);assert!(ps_line.contains("Get-Command git-wt"),"powershell should check for git-wt"@@ -560,7 +545,7 @@ mod tests {// All shells should return at least one config pathlet shells = [Shell::Bash, Shell::Zsh, Shell::Fish, Shell::PowerShell];for shell in shells {- let result = shell.config_paths();+ let result = shell.config_paths("wt");assert!(result.is_ok(), "Failed to get config paths for {:?}", shell);let paths = result.unwrap();assert!(@@ -576,7 +561,7 @@ mod tests {// All shells should return a completion pathlet shells = [Shell::Bash, Shell::Zsh, Shell::Fish, Shell::PowerShell];for shell in shells {- let result = shell.completion_path();+ let result = shell.completion_path("wt");assert!(result.is_ok(),"Failed to get completion path for {:?}",@@ -597,20 +582,20 @@ mod tests {let prefix = "custom-wt";// Fish config path should include prefix in filename- let fish_paths = Shell::Fish.config_paths_with_prefix(prefix).unwrap();+ let fish_paths = Shell::Fish.config_paths(prefix).unwrap();assert!(fish_paths[0].to_string_lossy().contains("custom-wt.fish"),"Fish config should include prefix in filename");// Bash and Zsh config paths are fixed (not affected by prefix)- let bash_paths = Shell::Bash.config_paths_with_prefix(prefix).unwrap();+ let bash_paths = Shell::Bash.config_paths(prefix).unwrap();assert!(bash_paths[0].to_string_lossy().contains(".bashrc"),"Bash config should be .bashrc");- let zsh_paths = Shell::Zsh.config_paths_with_prefix(prefix).unwrap();+ let zsh_paths = Shell::Zsh.config_paths(prefix).unwrap();assert!(zsh_paths[0].to_string_lossy().contains(".zshrc"),"Zsh config should be .zshrc"@@ -622,44 +607,27 @@ mod tests {let prefix = "my-prefix";// Bash completion should include prefix in path- let bash_path = Shell::Bash.completion_path_with_prefix(prefix).unwrap();+ let bash_path = Shell::Bash.completion_path(prefix).unwrap();assert!(bash_path.to_string_lossy().contains("my-prefix"),"Bash completion should include prefix");// Fish completion should include prefix in filename- let fish_path = Shell::Fish.completion_path_with_prefix(prefix).unwrap();+ let fish_path = Shell::Fish.completion_path(prefix).unwrap();assert!(fish_path.to_string_lossy().contains("my-prefix.fish"),"Fish completion should include prefix in filename");// Zsh completion should include prefix- let zsh_path = Shell::Zsh.completion_path_with_prefix(prefix).unwrap();+ let zsh_path = Shell::Zsh.completion_path(prefix).unwrap();assert!(zsh_path.to_string_lossy().contains("_my-prefix"),"Zsh completion should include underscore prefix");}- #[test]- fn test_config_line_prefix_arg_handling() {- // Default prefix should not include --cmd- let bash_default = Shell::Bash.config_line_with_prefix("wt");- assert!(- !bash_default.contains("--cmd"),- "Default prefix should not include --cmd"- );-- // Custom prefix should include --cmd- let bash_custom = Shell::Bash.config_line_with_prefix("custom");- assert!(- bash_custom.contains("--cmd=custom"),- "Custom prefix should include --cmd=custom"- );- }-#[test]fn test_shell_init_with_custom_prefix() {let init = ShellInit::with_prefix(Shell::Bash, "custom".to_string());@@ -672,7 +640,7 @@ mod tests {);}- /// Verify that `config_line_with_prefix()` generates lines that+ /// Verify that `config_line()` generates lines that/// `is_shell_integration_line()` can detect.////// This prevents install and detection from drifting out of sync.@@ -681,10 +649,10 @@ mod tests {#[values(Shell::Bash, Shell::Zsh, Shell::Fish, Shell::PowerShell)] shell: Shell,#[values("wt", "git-wt")] prefix: &str,) {- let line = shell.config_line_with_prefix(prefix);+ let line = shell.config_line(prefix);assert!(is_shell_integration_line(&line, prefix),- "{shell} config_line_with_prefix({prefix:?}) not detected:\n {line}"+ "{shell} config_line({prefix:?}) not detected:\n {line}");}}