Last active
December 30, 2015 16:18
-
-
Save hSATAC/7853379 to your computer and use it in GitHub Desktop.
Run vim from go just like `git commit`
proof of concept
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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