1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/utils/fuzzy_search.go
2022-03-24 20:14:41 +11:00

22 lines
360 B
Go

package utils
import (
"sort"
"github.com/jesseduffield/generics/slices"
"github.com/sahilm/fuzzy"
)
func FuzzySearch(needle string, haystack []string) []string {
if needle == "" {
return []string{}
}
matches := fuzzy.Find(needle, haystack)
sort.Sort(matches)
return slices.Map(matches, func(match fuzzy.Match) string {
return match.Str
})
}