-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgs.go
97 lines (82 loc) · 1.39 KB
/
gs.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
85
86
87
88
89
90
91
92
93
94
95
96
97
// flag index
const (
Clean = iota
Utracked = iota
uncommited = iota
unpushed = iota
unpulled = iota
restore = iota
FlagLen = iota
)
// flag texts
var (
FlagTexts = []string{
"working tree clean",
"Untracked files",
"Changes to be committed",
"Your branch is ahead",
"behind",
"Changes not staged for commit",
}
FlagIcons = []string{
"✓",
"+",
"→",
"↑",
"↓",
"*",
}
flags = make([]bool, FlagLen)
)
var (
OK string
Upload string
Commit string
)
func InitGs () {
//Ok
OK = colors["GS.git.OK"]
//local commit -> remote
Upload = colors["GS.git.ToUpload"]
//local Update -> commit
Commit = colors["GS.git.ToUpdate"]
}
func GetGs ( dir string ) (string) {
var (
GSOut string
branch string
)
cmd := exec.Command("git", "status")
cmd.Dir = dir
Out, err := cmd.Output()
// not git directory
if err != nil{
// TODO(5): cfg/show no .git
PS(err)
return "[no .git]"
}
GSOut = string(Out)
branch = strings.Split(GSOut, "\n")[0]
branch = strings.Join(strings.Split(branch, " ")[2:], " ")
for i:=0;i<FlagLen;i++ {
flags[i] = strings.Contains(GSOut, FlagTexts[i])
}
if branch != "master" && branch != "main" {
GSOut = branch+" "
} else {
GSOut = ""
}
if flags[0] {
GSOut += OK
} else if flags[3] {
GSOut += Upload
} else {
GSOut += Commit
}
for i:=0;i<FlagLen;i++ {
if flags[i] {
GSOut += FlagIcons[i]
}
}
return GSOut
}