Skip to content

Commit

Permalink
Denote installed packages when searching (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
jolheiser authored Sep 28, 2022
1 parent 14eae1d commit b3c3df5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cmd/search/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,19 @@ The "search" subcommand starts an interactive window to find and display info ab
return pkgInfos[i].Title < pkgInfos[j].Title
})

installed := utils.InstalledPackages()
installedSet := make(map[string]struct{})
for _, i := range installed {
installedSet[i] = struct{}{}
}
idx, err := fuzzyfinder.Find(
pkgInfos,
func(i int) string {
return pkgInfos[i].Title + " - " + pkgInfos[i].Tagline
pre := " "
if _, ok := installedSet[pkgInfos[i].Title]; ok {
pre = "✅ "
}
return pre + pkgInfos[i].Title + " - " + pkgInfos[i].Tagline
},
fuzzyfinder.WithPreviewWindow(func(i, w, h int) string {
if i == -1 {
Expand Down
13 changes: 13 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,16 @@ func ParseStem(pkgVerStem string) (string, string) {
pkg, ver, _ := strings.Cut(pkgVerStem, "-")
return pkg, ver
}

// InstalledPackages returns a list of currently installed packages, as per the webman pkgs directory
func InstalledPackages() []string {
var pkgs []string
entries, err := os.ReadDir(WebmanPkgDir)
if err != nil {
return nil
}
for _, entry := range entries {
pkgs = append(pkgs, entry.Name())
}
return pkgs
}

0 comments on commit b3c3df5

Please sign in to comment.