mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-14 11:23:09 +02:00
24 lines
348 B
Go
24 lines
348 B
Go
|
package utils
|
||
|
|
||
|
import (
|
||
|
"sort"
|
||
|
|
||
|
"github.com/sahilm/fuzzy"
|
||
|
)
|
||
|
|
||
|
func FuzzySearch(needle string, haystack []string) []string {
|
||
|
if needle == "" {
|
||
|
return []string{}
|
||
|
}
|
||
|
|
||
|
matches := fuzzy.Find(needle, haystack)
|
||
|
sort.Sort(matches)
|
||
|
|
||
|
result := make([]string, len(matches))
|
||
|
for i, match := range matches {
|
||
|
result[i] = match.Str
|
||
|
}
|
||
|
|
||
|
return result
|
||
|
}
|