Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
default to current branch
  • Loading branch information
skarim committed Apr 18, 2026
commit e86589da2d26597c27b236e757613e1eb412cd0c
9 changes: 6 additions & 3 deletions cmd/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ func runSwitch(cfg *config.Config) error {
// Build options in reverse order (top of stack first) with 1-based numbering.
n := len(s.Branches)
options := make([]string, n)
currentBranch := result.CurrentBranch
var defaultOpt string
for i := 0; i < n; i++ {
branchIdx := n - 1 - i
options[i] = fmt.Sprintf("%d. %s", branchIdx+1, s.Branches[branchIdx].Branch)
if s.Branches[branchIdx].Branch == currentBranch {
defaultOpt = options[i]
}
}

var selectFn func(prompt, def string, opts []string) (int, error)
Expand All @@ -60,7 +65,7 @@ func runSwitch(cfg *config.Config) error {
}
}

selected, err := selectFn("Select a branch in the stack to switch to:", "", options)
selected, err := selectFn("Select a branch in the stack to switch to:", defaultOpt, options)
if err != nil {
if isInterruptError(err) {
clearSelectPrompt(cfg, len(options))
Expand All @@ -79,8 +84,6 @@ func runSwitch(cfg *config.Config) error {
// Map selection back: index 0 in options = branch at n-1, etc.
branchIdx := n - 1 - selected
targetBranch := s.Branches[branchIdx].Branch
Comment thread
skarim marked this conversation as resolved.

currentBranch := result.CurrentBranch
if targetBranch == currentBranch {
cfg.Infof("Already on %s", targetBranch)
return nil
Expand Down