-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
flake.go
45 lines (40 loc) · 1.06 KB
/
flake.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package nix
import (
"strings"
"time"
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace/pkg/style"
)
// ActionFlakes completes flakes currently available
//
// nixpkgs
// .
func ActionFlakes() carapace.Action {
return carapace.ActionExecCommand("nix", "registry", "list")(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
vals := make([]string, 0)
// `nix registry list` outputs a blank line after the listings
for _, line := range lines[:len(lines)-1] {
fields := strings.Fields(line)
name := strings.Split(fields[1], ":")
if name[0] == "flake" {
vals = append(vals, name[1], fields[2], styleForRegistry(fields[0]))
}
}
return carapace.Batch(
carapace.ActionValues(".", "..").StyleF(style.ForPath),
carapace.ActionDirectories(),
carapace.ActionStyledValuesDescribed(vals...),
).ToA()
}).Cache(time.Minute).Suffix("#")
}
func styleForRegistry(s string) string {
switch s {
case "global":
return style.Blue
case "system":
return style.Yellow
default:
return style.Default
}
}