Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Refactor: Simplify worktree path extraction
Maximilian Roosc67aab6b62bc
diff --git a/src/commands/list/layout.rs b/src/commands/list/layout.rsindex 2356cba97..80aeecb78 100644--- a/src/commands/list/layout.rs+++ b/src/commands/list/layout.rs@@ -183,10 +183,7 @@ pub fn calculate_responsive_layout(items: &[ListItem]) -> LayoutConfig {let terminal_width = get_terminal_width();let paths: Vec<&Path> = items.iter()- .filter_map(|item| match item {- ListItem::Worktree(info) => Some(info.worktree.path.as_path()),- ListItem::Branch(_) => None,- })+ .filter_map(|item| item.worktree_path().map(|path| path.as_path())).collect();let common_prefix = find_common_prefix(&paths);@@ -196,14 +193,11 @@ pub fn calculate_responsive_layout(items: &[ListItem]) -> LayoutConfig {// Calculate actual maximum path width (after common prefix removal)let max_path_width = items.iter()- .filter_map(|item| match item {- ListItem::Worktree(info) => Some(info),- ListItem::Branch(_) => None,- })- .map(|info| {+ .filter_map(|item| item.worktree_path())+ .map(|path| {use crate::display::shorten_path;use unicode_width::UnicodeWidthStr;- shorten_path(&info.worktree.path, &common_prefix).width()+ shorten_path(path.as_path(), &common_prefix).width()}).max().unwrap_or(20); // fallback to 20 if no pathsdiff --git a/src/commands/list/mod.rs b/src/commands/list/mod.rsindex 312225e57..bc62078c2 100644--- a/src/commands/list/mod.rs+++ b/src/commands/list/mod.rs@@ -208,6 +208,10 @@ impl ListItem {ListItem::Branch(_) => None,}}++ pub fn worktree_path(&self) -> Option<&std::path::PathBuf> {+ self.worktree_info().map(|info| &info.worktree.path)+ }}impl BranchInfo {