forked from justjanne/powerline-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
segment-fossil.go
76 lines (64 loc) · 1.65 KB
/
segment-fossil.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
package main
import (
"fmt"
pwl "github.com/justjanne/powerline-go/powerline"
"os/exec"
"strings"
)
func getFossilStatus() (bool, bool, bool) {
hasModifiedFiles := false
hasUntrackedFiles := false
hasMissingFiles := false
out, err := exec.Command("fossil", "changes", "--differ").Output()
if err == nil {
output := strings.Split(string(out), "\n")
for _, line := range output {
if line != "" {
if strings.HasPrefix(line, "EXTRA") {
hasUntrackedFiles = true
} else if strings.HasPrefix(line, "MISSING") {
hasMissingFiles = true
} else {
hasModifiedFiles = true
}
}
}
}
return hasModifiedFiles, hasUntrackedFiles, hasMissingFiles
}
func segmentFossil(p *powerline) []pwl.Segment {
out, _ := exec.Command("fossil", "branch", "current").Output()
output := strings.SplitN(string(out), "\n", 2)
if len(output) > 0 && output[0] != "" {
branch := output[0]
hasModifiedFiles, hasUntrackedFiles, hasMissingFiles := getFossilStatus()
var foreground, background uint8
var content string
if hasModifiedFiles || hasUntrackedFiles || hasMissingFiles {
foreground = p.theme.RepoDirtyFg
background = p.theme.RepoDirtyBg
extra := ""
if hasUntrackedFiles {
extra += "+"
}
if hasMissingFiles {
extra += "!"
}
if hasUntrackedFiles {
extra += "?"
}
content = fmt.Sprintf("%s %s", branch, extra)
} else {
foreground = p.theme.RepoCleanFg
background = p.theme.RepoCleanBg
content = fmt.Sprintf(branch)
}
return []pwl.Segment{{
Name: "fossil",
Content: content,
Foreground: foreground,
Background: background,
}}
}
return []pwl.Segment{}
}