Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Prioritize current worktree in list output
Maximilian Roosde7cc4a3fdfa
diff --git a/src/commands/list/collect.rs b/src/commands/list/collect.rsindex 65f45b3ea..1ed863186 100644--- a/src/commands/list/collect.rs+++ b/src/commands/list/collect.rs@@ -322,7 +322,7 @@ pub fn collect(let current_worktree_path = repo.worktree_root().ok();let previous_branch = repo.get_switch_history().and_then(|h| h.previous);- // Sort worktrees: main first, current second, then by timestamp descending+ // Sort worktrees: current first, main second, then by timestamp descendinglet sorted_worktrees = sort_worktrees(worktrees.worktrees.clone(),&main_worktree,@@ -708,7 +708,7 @@ whereindexed.into_iter().map(|(_, item)| item).collect()}-/// Sort worktrees: main first, current second, then by timestamp descending.+/// Sort worktrees: current first, main second, then by timestamp descending.fn sort_worktrees(worktrees: Vec<Worktree>,main_worktree: &Worktree,@@ -725,10 +725,10 @@ fn sort_worktrees(let mut indexed: Vec<_> = worktrees.into_iter().enumerate().collect();indexed.sort_by_key(|(idx, wt)| {- let priority = if wt.path == main_worktree.path {- 0 // Main first- } else if current_path.map(|cp| &wt.path == cp).unwrap_or(false) {- 1 // Current second+ let priority = if current_path.map(|cp| &wt.path == cp).unwrap_or(false) {+ 0 // Current first+ } else if wt.path == main_worktree.path {+ 1 // Main second} else {2 // Rest by timestamp};diff --git a/src/commands/list/mod.rs b/src/commands/list/mod.rsindex bb6ed6c72..516f652cb 100644--- a/src/commands/list/mod.rs+++ b/src/commands/list/mod.rs@@ -19,7 +19,7 @@//! - Refresh with `wt config cache refresh`//!//! 3. **Sort worktrees** (<1ms)-//! - Orders by: current → main → rest alphabetically+//! - Orders by: current → main → rest by timestamp (most recent first)//! - Pure Rust, no git calls//!//! 4. **Branch listing** (only with `--branches`, ~10-30ms)diff --git a/src/commands/select.rs b/src/commands/select.rsindex 4cdf634f6..f0339d19f 100644--- a/src/commands/select.rs+++ b/src/commands/select.rs@@ -496,9 +496,6 @@ pub fn handle_select(is_directive_mode: bool) -> anyhow::Result<()> {return Ok(());};- // Get current worktree path for styling- let _current_worktree_path = repo.worktree_root().ok();-// Use the same layout system as `wt list` for proper column alignment// Skim uses ~50% of terminal width for the list (rest is preview), so calculate// layout based on available width to avoid truncationdiff --git a/tests/snapshots/integration__integration_tests__list__list_ordering_rules.snap b/tests/snapshots/integration__integration_tests__list__list_ordering_rules.snapindex aa9076884..6e9580db4 100644--- a/tests/snapshots/integration__integration_tests__list__list_ordering_rules.snap+++ b/tests/snapshots/integration__integration_tests__list__list_ordering_rules.snap@@ -24,8 +24,8 @@ exit_code: 0----- stderr -----[1mBranch[0m [1mStatus[0m [1mHEAD±[0m [1mmain↕[0m [1mPath[0m [1mRemote⇅[0m [1mCommit[0m [1mAge[0m [1mMessage[0m-^ main [2m^[0m ./repo [2m6c3da842[0m [2m1d[0m [2mInitial commit on main[0m@ [1mfeature-current[0m [2m↑[0m [32m↑1[0m [1m./repo.feature-current[0m [2mfc28a4d1[0m [2m23h[0m [2mCommit at 01:00[0m+^ main [2m^[0m ./repo [2m6c3da842[0m [2m1d[0m [2mInitial commit on main[0m+ feature-newest [2m↑[0m [32m↑1[0m ./repo.feature-newest [2m136358eb[0m [2m21h[0m [2mCommit at 03:00[0m+ feature-middle [2m↑[0m [32m↑1[0m ./repo.feature-middle [2ma0a4851a[0m [2m22h[0m [2mCommit at 02:00[0m+ feature-oldest [2m↑[0m [32m↑1[0m ./repo.feature-oldest [2m1b1a2d78[0m [2m23h[0m [2mCommit at 00:30[0mdiff --git a/tests/snapshots/integration__integration_tests__list__task_dag_ordering_stability.snap b/tests/snapshots/integration__integration_tests__list__task_dag_ordering_stability.snapindex 08c1b091e..ebbdcec92 100644--- a/tests/snapshots/integration__integration_tests__list__task_dag_ordering_stability.snap+++ b/tests/snapshots/integration__integration_tests__list__task_dag_ordering_stability.snap@@ -25,8 +25,8 @@ exit_code: 0----- stderr -----[1mBranch[0m [1mStatus[0m [1mHEAD±[0m [1mmain↕[0m [1mPath[0m [1mRemote⇅[0m [1mCommit[0m [1mAge[0m [1mMessage[0m-^ main [2m^[0m ./repo [2m6c3da842[0m [2m1d[0m [2mInitial commit on main[0m@ [1mfeature-current[0m [2m↑[0m [32m↑1[0m [1m./repo.feature-current[0m [2mfc28a4d1[0m [2m23h[0m [2mCommit at 01:00[0m+^ main [2m^[0m ./repo [2m6c3da842[0m [2m1d[0m [2mInitial commit on main[0m+ feature-newest [2m↑[0m [32m↑1[0m ./repo.feature-newest [2m136358eb[0m [2m21h[0m [2mCommit at 03:00[0m+ feature-middle [2m↑[0m [32m↑1[0m ./repo.feature-middle [2ma0a4851a[0m [2m22h[0m [2mCommit at 02:00[0m+ feature-oldest [2m↑[0m [32m↑1[0m ./repo.feature-oldest [2m1b1a2d78[0m [2m23h[0m [2mCommit at 00:30[0m