Skip to content

Instantly share code, notes, and snippets.

@Tethik
Last active August 1, 2020 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tethik/bbd4eaec2b67f9e8eb3696fe0689330a to your computer and use it in GitHub Desktop.
Save Tethik/bbd4eaec2b67f9e8eb3696fe0689330a to your computer and use it in GitHub Desktop.
not so efficient file searching
type Searcher struct {
data []*DesktopApp
}
func SearcherNew() *Searcher {
// TODO: might be worth caching / indexing here somehow.
var all []*DesktopApp
paths := applicationDirs()
log.Infof("Application dirs:\n %s", paths)
seen := map[string]bool{}
for _, p := range paths {
apps := enumerateDirForApps(p)
for _, a := range apps {
// Lazy way to filter out duplicates
if _, ok := seen[a.Name]; !ok {
all = append(all, a)
seen[a.Name] = true
}
}
}
return &Searcher{all}
}
func (s *Searcher) SearchApps(text string) (result []*DesktopApp) {
for _, a := range s.data {
// Lazy solution for now.
if strings.Contains(strings.ToLower(a.Name), strings.ToLower(text)) {
result = append(result, a)
}
}
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment