@@ 16,10 16,9 @@ func wipe() {
win.Write("data", nil)
}
-func status() {
+func gitcmd(arg ...string) {
wipe()
-
- cmd := exec.Command("git", "status")
+ cmd := exec.Command("git", arg...)
r, w, err := os.Pipe()
if err != nil {
log.Fatal(err)
@@ 46,6 45,14 @@ func status() {
}
}
+func diff() {
+ gitcmd("diff")
+}
+
+func status() {
+ gitcmd("status")
+}
+
func commit() {
// I can see a couple of ways to implement "commit". (1) Open another buffer
// to hold the commit message, and when closing that buffer capture the content
@@ 54,8 61,34 @@ func commit() {
wipe()
// Call mktemp, get the file name
// Run the following:
- // GIT_EDITOR=./acme-ed.sh git commit -e -F /tmp/tmp.RS2v3ssoXL
-}
+ // GIT_EDITOR=./acme-ed.sh git commit
+ // Our "editor" will be acme-ed, that pops open the file provided by git and monitors the index (or the events?) to exit only when the commit message buffer gets closed.
+
+ cmd := exec.Command("git", "commit")
+ r, w, err := os.Pipe()
+ if err != nil {
+ log.Fatal(err)
+ }
+ cmd.Stdout = w
+ cmd.Stderr = w
+
+ cmd.Env = append(os.Environ(), "GIT_EDITOR=acme-ed.sh")
+ err = cmd.Start()
+ w.Close()
+ if err != nil {
+ r.Close()
+ win.Fprintf("data", "(exec: %s)\n", err)
+ }
+ buf := make([]byte, 4096)
+ for {
+ n, err := r.Read(buf)
+ if err != nil {
+ break
+ }
+ if n > 0 {
+ win.Write("data", buf)
+ }
+ }}
func main() {
var err error
@@ 70,7 103,6 @@ func main() {
win.Ctl("clean")
win.Fprintf("tag", "Status Diff Log Commit")
- //win.Fprintf("body", "PLACEHOLDER")
go events()
r, err := acme.Log()
@@ 83,8 115,9 @@ func main() {
log.Fatal(err)
}
if ev.Op == "put" {
- fmt.Println("Saved!")
+ ; //fmt.Println("Saved!")
}
+ //fmt.Printf("%+v\n", ev)
}
}
@@ 98,6 131,10 @@ func events() {
win.Ctl("delete")
case "Status":
status()
+ case "Diff":
+ diff()
+ case "Commit":
+ commit()
default:
fmt.Println(text)
}