forked from justjanne/powerline-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
segment-bzr.go
76 lines (64 loc) · 1.55 KB
/
segment-bzr.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 getBzrStatus() (bool, bool, bool) {
hasModifiedFiles := false
hasUntrackedFiles := false
hasMissingFiles := false
out, err := exec.Command("bzr", "status").Output()
if err == nil {
output := strings.Split(string(out), "\n")
for _, line := range output {
if line != "" {
if line == "unknown:" {
hasUntrackedFiles = true
} else if line == "missing:" {
hasMissingFiles = true
} else {
hasModifiedFiles = true
}
}
}
}
return hasModifiedFiles, hasUntrackedFiles, hasMissingFiles
}
func segmentBzr(p *powerline) []pwl.Segment {
out, _ := exec.Command("bzr", "nick").Output()
output := strings.SplitN(string(out), "\n", 2)
if len(output) > 0 && output[0] != "" {
branch := output[0]
hasModifiedFiles, hasUntrackedFiles, hasMissingFiles := getBzrStatus()
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 = branch
}
return []pwl.Segment{{
Name: "bzr",
Content: content,
Foreground: foreground,
Background: background,
}}
}
return []pwl.Segment{}
}