Skip to content

Instantly share code, notes, and snippets.

@hSATAC
Last active December 30, 2015 16:18
Show Gist options
  • Save hSATAC/7853379 to your computer and use it in GitHub Desktop.
Save hSATAC/7853379 to your computer and use it in GitHub Desktop.
Run vim from go just like `git commit` proof of concept
package main
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
)
var (
editor string = "vim"
filename string = "test"
)
func main() {
cleanFile()
runEditor()
content := readFile()
fmt.Println(content)
cleanFile()
}
func runEditor() {
cmd := exec.Command(editor, filename)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
cmd.Run()
}
func cleanFile() {
os.Remove(filename)
}
func readFile() (content string) {
bs, _ := ioutil.ReadFile(filename)
content = string(bs)
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment