diff --git a/README.md b/README.md index 93d7f84..a46343b 100644 --- a/README.md +++ b/README.md @@ -728,3 +728,62 @@ Credit: @cobaltblu27 *Yeah exiting vim is really frustrating sometimes. You should definately try using Neovim. It's fast, has terminal emulator, and also supports plugin that will help you exit vim.* +## The Go Way + +1. Make sure that you have Go installed +2. Write a whole application to find and kill vim + +```go +package main + +import ( + "bytes" + "io/ioutil" + "log" + "os" + "path/filepath" + "strconv" + "strings" +) + +func TerminateVim(path string, info os.FileInfo, err error) error { + var proc []int + if strings.Count(path, "/") == 3 { + if strings.Contains(path, "/status") { + pid, err := strconv.Atoi(path[6:strings.LastIndex(path, "/")]) + if err != nil { + return err + } + f, err := ioutil.ReadFile(path) + if err != nil { + return err + } + name := string(f[6:bytes.IndexByte(f, '\n')]) + if name == "vim" { + log.Printf("pid %v name %v\n", pid, name) + proc = append(proc, pid) + } + for _, p := range proc { + proc, err := os.FindProcess(p) + if err != nil { + return err + } + proc.Kill() + } + return nil + } + } + return nil +} + +func main() { + err := filepath.Walk("/proc", TerminateVim) + if err != nil { + log.Fatalln(err) + } + log.Printf("Killed vim\n") +} +``` + +3. Run with `go run .` or make executable using `go build -o VimKill` +