mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Display current git repo and branch
This commit is contained in:
parent
f6e7a2c030
commit
e1e8af5e38
@ -1,15 +1,63 @@
|
||||
package git
|
||||
|
||||
import ()
|
||||
import (
|
||||
//"fmt"
|
||||
"io/ioutil"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
Repository string
|
||||
CommitCount int
|
||||
Repository string
|
||||
}
|
||||
|
||||
func NewClient() *Client {
|
||||
client := Client{
|
||||
Repository: "./Documents/Lendesk/core-api",
|
||||
CommitCount: 10,
|
||||
Repository: "/Users/Chris/Documents/Lendesk/core-api",
|
||||
}
|
||||
|
||||
return &client
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func (client *Client) CurrentBranch() string {
|
||||
arg := []string{"rev-parse", "--abbrev-ref", "HEAD"}
|
||||
cmd := exec.Command("git", arg...)
|
||||
str := executeCommand(cmd)
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
func (client *Client) ChangedFiles() []string {
|
||||
files := []string{}
|
||||
|
||||
return files
|
||||
}
|
||||
|
||||
func (client *Client) Commits() []string {
|
||||
files := []string{}
|
||||
|
||||
return files
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func executeCommand(cmd *exec.Cmd) string {
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
return "err"
|
||||
}
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
return "err"
|
||||
}
|
||||
|
||||
var str string
|
||||
if b, err := ioutil.ReadAll(stdout); err == nil {
|
||||
str += string(b)
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
|
16
git/git.go
Normal file
16
git/git.go
Normal file
@ -0,0 +1,16 @@
|
||||
package git
|
||||
|
||||
import ()
|
||||
|
||||
func Fetch() map[string][]string {
|
||||
client := NewClient()
|
||||
|
||||
result := make(map[string][]string)
|
||||
|
||||
result["repo"] = []string{client.Repository}
|
||||
result["branch"] = []string{client.CurrentBranch()}
|
||||
result["changed"] = client.ChangedFiles()
|
||||
result["commits"] = client.Commits()
|
||||
|
||||
return result
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
//"fmt"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
@ -31,13 +31,13 @@ func NewWidget() *Widget {
|
||||
/* -------------------- Exported Functions -------------------- */
|
||||
|
||||
func (widget *Widget) Refresh() {
|
||||
//data := Fetch()
|
||||
data := Fetch()
|
||||
|
||||
widget.View.SetTitle(" 🙈 Git ")
|
||||
widget.View.SetTitle(" 🤞 Git ")
|
||||
widget.RefreshedAt = time.Now()
|
||||
|
||||
widget.View.Clear()
|
||||
//fmt.Fprintf(widget.View, "%s", widget.contentFrom(data))
|
||||
fmt.Fprintf(widget.View, "%s", widget.contentFrom(data))
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
@ -52,9 +52,10 @@ func (widget *Widget) addView() {
|
||||
widget.View = view
|
||||
}
|
||||
|
||||
func (widget *Widget) contentFrom(data map[string]string) string {
|
||||
func (widget *Widget) contentFrom(data map[string][]string) string {
|
||||
str := "\n"
|
||||
str = str + "This is git"
|
||||
str = str + fmt.Sprintf(" [green]%s[white] [grey]%s[white]\n", data["repo"][0], data["branch"][0])
|
||||
str = str + "\n"
|
||||
|
||||
return str
|
||||
}
|
||||
|
@ -8,36 +8,32 @@ import (
|
||||
|
||||
const osxFirewallCmd = "/usr/libexec/ApplicationFirewall/socketfilterfw"
|
||||
|
||||
/* -------------------- Exported Functions -------------------- */
|
||||
|
||||
func FirewallState() string {
|
||||
cmd := exec.Command(osxFirewallCmd, "--getglobalstate")
|
||||
str := executeCommand(cmd)
|
||||
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
return firewallIcon("err")
|
||||
}
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
return firewallIcon("err")
|
||||
}
|
||||
|
||||
var str string
|
||||
if b, err := ioutil.ReadAll(stdout); err == nil {
|
||||
str += string(b)
|
||||
}
|
||||
|
||||
return firewallIcon(str)
|
||||
return str
|
||||
}
|
||||
|
||||
func FirewallStealthState() string {
|
||||
cmd := exec.Command(osxFirewallCmd, "--getstealthmode")
|
||||
str := executeCommand(cmd)
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func executeCommand(cmd *exec.Cmd) string {
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
return firewallIcon("err")
|
||||
return firewallStr("err")
|
||||
}
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
return firewallIcon("err")
|
||||
return firewallStr("err")
|
||||
}
|
||||
|
||||
var str string
|
||||
@ -45,10 +41,10 @@ func FirewallStealthState() string {
|
||||
str += string(b)
|
||||
}
|
||||
|
||||
return firewallIcon(str)
|
||||
return firewallStr(str)
|
||||
}
|
||||
|
||||
func firewallIcon(str string) string {
|
||||
func firewallStr(str string) string {
|
||||
icon := "[red]off[white]"
|
||||
|
||||
if strings.Contains(str, "enabled") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user