-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (40 loc) · 838 Bytes
/
main.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
46
47
48
49
50
package main
import (
"fmt"
"sort"
"strings"
"github.com/chickenzord/envprompt/profile"
"github.com/fatih/color"
)
var (
profiles = map[string]profile.Profile{
"chef": *profile.NewChefProfile("c"),
"kube": *profile.NewKubeProfile("k"),
}
)
func renderPrompt(p profile.Profile) string {
label := p.Label
val := p.GetValue()
if val == "" || val == p.Default {
return ""
}
c := color.New()
if strings.Contains(val, "-prd") {
c = c.Add(color.FgRed)
}
return fmt.Sprintf("%s:%s", label, c.Sprintf(val))
}
func main() {
keys := []string{}
for key, _ := range profiles {
keys = append(keys, key)
}
sort.Strings(keys)
parts := []string{}
for _, k := range keys {
// p :=
parts = append(parts, renderPrompt(profiles[k]))
}
prompt := strings.TrimSpace(strings.Join(parts, " "))
fmt.Println(prompt)
}