Skip to content
Draft
Changes from all commits
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
27 changes: 27 additions & 0 deletions pkg/tui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package tui
import (
"fmt"
"os"
"path/filepath"
"strings"

storetypes "github.com/MichaelSp/kswitch/pkg/store/types"
Expand Down Expand Up @@ -126,6 +127,21 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

case discoveryDoneMsg:
m.loading = false
// Disambiguate items that share a contextName by showing the source path.
nameCounts := make(map[string]int)
for _, it := range m.allItems {
nameCounts[it.contextName]++
}
changed := false
for i, it := range m.allItems {
if nameCounts[it.contextName] > 1 && it.dimSuffix == "" {
m.allItems[i].dimSuffix = shortPath(it.path)
changed = true
}
}
if changed {
m.filtered = filterItems(m.query, m.allItems)
}
return m, nil

case previewMsg:
Expand Down Expand Up @@ -423,3 +439,14 @@ func truncate(s string, max int) string {
}
return string(r[:max-2]) + ".."
}

// shortPath returns up to the last 2 path components of p (e.g. "configs/prod.yaml").
func shortPath(p string) string {
dir := filepath.Dir(p)
base := filepath.Base(p)
parent := filepath.Base(dir)
if parent == "." || parent == "/" {
return base
}
return parent + "/" + base
}