-
Notifications
You must be signed in to change notification settings - Fork 0
/
git.go
48 lines (39 loc) · 1.04 KB
/
git.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
package main
import (
"bufio"
"bytes"
"fmt"
"os/exec"
"strings"
"github.com/charmbracelet/bubbles/list"
)
func gitBranch() string {
cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
result, err := cmd.CombinedOutput()
if err != nil {
panic(fmt.Sprintf("%s\n%v", result, err))
}
scanner := bufio.NewScanner(bytes.NewBuffer(result))
scanner.Scan()
return scanner.Text()
}
func gitLog(num int) []list.Item {
cmd := exec.Command("git", "log", "--oneline", fmt.Sprintf("-%d", num), "--pretty=%s;%h;%an;%cr;%d")
result, err := cmd.CombinedOutput()
if err != nil {
panic(fmt.Sprintf("%s\n%v", result, err))
}
items := make([]list.Item, 0)
scanner := bufio.NewScanner(bytes.NewBuffer(result))
for scanner.Scan() {
line := scanner.Text()
record := strings.Split(line, ";")
desc := fmt.Sprintf("%s • %s • %s", record[1], record[2], record[3])
if record[4] != "" {
desc = fmt.Sprintf("%s • %s", desc, record[4])
}
item := item{title: record[0], desc: desc}
items = append(items, item)
}
return items
}