From 84f2c8f49a82a197a36eae3fdaa3ee1af4ec05c5 Mon Sep 17 00:00:00 2001 From: VERSE Date: Mon, 27 Jul 2026 20:05:44 +0700 Subject: [PATCH] fix(history): fuzzy search not working (#44) quick fix, please read commit I'm too lazy to write description of changes --- integration/history.go | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/integration/history.go b/integration/history.go index b06c537..72ce2e3 100644 --- a/integration/history.go +++ b/integration/history.go @@ -208,12 +208,20 @@ func SearchHistory(query string, aliases map[string]string) ([]HistResult, error var results []HistResult seenCmds := make(map[string]bool) - addMatches := func(q string) { + addMatches := func(q string, subcmdFilter bool) { qLow := strings.ToLower(q) queryFirstWord := "" + querySecondWord := "" if strings.IndexByte(qLow, ' ') != -1 { if fields := strings.Fields(qLow); len(fields) > 0 { queryFirstWord = fields[0] + // find first non-flag token after the command as the subcommand + for _, f := range fields[1:] { + if !strings.HasPrefix(f, "-") { + querySecondWord = f + break + } + } } } @@ -224,9 +232,10 @@ func SearchHistory(query string, aliases map[string]string) ([]HistResult, error } // filter results by command name match + fields := strings.Fields(m.Str) firstWord := m.Str - if idx := strings.IndexByte(m.Str, ' '); idx != -1 { - firstWord = m.Str[:idx] + if len(fields) > 0 { + firstWord = fields[0] } firstWordLow := strings.ToLower(firstWord) @@ -234,6 +243,16 @@ func SearchHistory(query string, aliases map[string]string) ([]HistResult, error if firstWordLow != queryFirstWord { continue } + // when query has a non-flag second token, filter by subcommand prefix + if subcmdFilter && querySecondWord != "" { + if len(fields) < 2 { + continue + } + secondWordLow := strings.ToLower(fields[1]) + if !strings.HasPrefix(secondWordLow, querySecondWord) { + continue + } + } } else { if !strings.HasPrefix(firstWordLow, qLow) { continue @@ -249,10 +268,18 @@ func SearchHistory(query string, aliases map[string]string) ([]HistResult, error } } - addMatches(query) - + addMatches(query, true) for _, altQ := range alternativeQueries { - addMatches(altQ) + addMatches(altQ, true) + } + + // fallback: if subcommand filter produced nothing, retry without it + // so typos like "git chckout" still surface fuzzy matches + if len(results) == 0 { + addMatches(query, false) + for _, altQ := range alternativeQueries { + addMatches(altQ, false) + } } getTier := func(cmd, q string) int {