-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
56 lines (43 loc) · 847 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
51
52
53
54
55
56
package main
import (
"fmt"
"io"
"log"
"os"
"os/exec"
)
func main() {
SetTmuxStatusColor("yellow")
args := os.Args[1:]
if len(args) == 0 {
log.Fatalln("Not enough arguments")
}
cmd := exec.Command(args[0], args[1:]...)
stdout, err := cmd.StdoutPipe()
ExitIfErr(err)
stderr, err := cmd.StderrPipe()
ExitIfErr(err)
ExitIfErr(cmd.Start())
go io.Copy(os.Stdout, stdout)
go io.Copy(os.Stderr, stderr)
ExitIfErr(cmd.Wait())
if cmd.ProcessState.Success() {
SetTmuxStatusColor("green")
} else {
SetTmuxStatusColor("red")
}
}
func SetTmuxStatusColor(color string) error {
cmd := exec.Command("tmux", "set", "status-bg", color)
return cmd.Run()
}
func ExitIfErr(err error) {
if err != nil {
Exit(err)
}
}
func Exit(message interface{}) {
SetTmuxStatusColor("red")
fmt.Fprint(os.Stderr, message)
os.Exit(1)
}