## What's new - TOML config support - add config init command to justfile https://github.com/versenilvis/IRIS/pull/9/commits/a5bb6c23d74ca73385b3590d2eb275ce6429906b - add copy binary file to local bin on reload https://github.com/versenilvis/IRIS/pull/9/commits/4da3acdbc58c28f20fa0021d15fec82823ba392b - init config on setup https://github.com/versenilvis/IRIS/pull/9/commits/fb48b6bb832f38e24fab9211d92858bab9a58a07 ## Fix - add lsof to support macos because /proc filesystem is Linux-specific and does not exist on macOS 0439d829573864fcf902fc4127f7d45384bfab01 - git push doesnt suggest current branch, fix https://github.com/versenilvis/IRIS/pull/9/commits/b498532b401b764a4a1a2c70b3cb44b7caf72320 - use timeout context for lsof command in reload handler https://github.com/versenilvis/IRIS/pull/9/commits/1a2baee951e6538a729da12aedfe53960e51102d
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
package root
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/versenilvis/iris/commands/core"
|
|
"github.com/versenilvis/iris/config"
|
|
"github.com/versenilvis/iris/integration"
|
|
)
|
|
|
|
// mergeResults collects and dedupes suggestions for a query and mode
|
|
// example: mergeResults("git ", "spec")
|
|
func MergeResults(query string, mode string) []core.Suggestion {
|
|
if query == "" && mode != "history" {
|
|
debugLog("[Merge] Query empty, returning nil")
|
|
return nil
|
|
}
|
|
|
|
maxSugg := config.Get().UI.MaxSuggestions
|
|
normalizedQuery := strings.TrimSpace(query)
|
|
seen := make(map[string]bool)
|
|
deduped := []core.Suggestion{}
|
|
|
|
if mode == "history" {
|
|
histResults, _ := integration.SearchHistory(query)
|
|
for _, h := range histResults {
|
|
normalizedCmd := strings.TrimSpace(h.Cmd)
|
|
if seen[normalizedCmd] {
|
|
continue
|
|
}
|
|
seen[normalizedCmd] = true
|
|
deduped = append(deduped, core.Suggestion{
|
|
Cmd: h.Cmd,
|
|
Desc: " history",
|
|
Icon: fmt.Sprintf("%d", h.ID),
|
|
})
|
|
if len(deduped) >= maxSugg {
|
|
break
|
|
}
|
|
}
|
|
debugLog("[Merge] History mode found %d items", len(deduped))
|
|
return deduped
|
|
}
|
|
|
|
debugLog("[Merge] Calling Lookup for '%s'", query)
|
|
cmdResults := core.Lookup(query)
|
|
debugLog("[Merge] Lookup returned %d raw items", len(cmdResults))
|
|
|
|
for _, s := range cmdResults {
|
|
normalizedCmd := strings.TrimSpace(s.Cmd)
|
|
if normalizedCmd == normalizedQuery { // filter exact matches to avoid loops
|
|
debugLog("[Merge] Filtered EXACT MATCH: '%s'", normalizedCmd)
|
|
continue
|
|
}
|
|
|
|
if !seen[s.Cmd] {
|
|
seen[s.Cmd] = true
|
|
deduped = append(deduped, s)
|
|
}
|
|
}
|
|
if len(deduped) > maxSugg {
|
|
deduped = deduped[:maxSugg]
|
|
}
|
|
return deduped
|
|
}
|