-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
84 lines (63 loc) · 1.54 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"flag"
"fmt"
"os"
"strings"
"github.com/noxer/gops/color"
"github.com/noxer/gops/segments/common"
"github.com/noxer/gops/segments/git"
"github.com/noxer/gops/separator"
"github.com/noxer/gops/symbols"
)
var end = separator.Segment{
Text: " ",
Foreground: color.Default,
Background: color.Default,
}
func main() {
prompt := flag.String("p", "PS1", "prompt type to render (PS1 or PS2)")
shell := flag.String("s", "bash", "shell the prompt will be rendered for (bash or zsh)")
flag.Parse()
switch strings.ToUpper(*prompt) {
case "PS1", "1":
ps1(*shell)
case "PS2", "2":
ps2(*shell)
default:
flag.Usage()
os.Exit(1)
}
}
// ps1 renders the normal prompt
func ps1(shell string) {
escape := initializeEscape(shell)
var segs []separator.Segment
segs = common.AddUserAtHost(segs, true)
segs = common.AddDir(segs, true)
segs = common.AddNodeVersion(segs)
segs = git.Add(segs)
segs = append(segs, end)
fmt.Print(separator.Render(escape, segs...))
}
// ps2 renders the continuation prompt
func ps2(shell string) {
escape := initializeEscape(shell)
segs := []separator.Segment{
{Text: " " + string(symbols.Ellipsis) + " ", Foreground: color.LightGray, Background: color.DarkGray},
end,
}
fmt.Println(separator.Render(escape, segs...))
}
func initializeEscape(shell string) func(string) string {
switch shell {
case "bash":
return color.EscapeBASH
case "zsh":
return color.EscapeZSH
}
// no matching shell found, return empty escape function
return func(s string) string {
return s
}
}