Skip to content

Commit

Permalink
Adding editor flag
Browse files Browse the repository at this point in the history
  • Loading branch information
polvoazul committed Jul 11, 2024
1 parent b42128a commit 811e8b8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions vimv.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"flag"
"fmt"
"os"
"os/exec"
Expand All @@ -17,19 +18,24 @@ var cleanup_afterwards = true
func main() {
defer handleExit() // Needs to be on top

files := removeEmptyLines(os.Args[1:])
// Flags
editor := flag.String("editor", "vim", "Which editor to use?")
flag.Parse()
files := flag.Args()

files = removeEmptyLines(files)
validateInput(files)
tmpfolder, filelist := getTmpFile(files)
defer cleanup(tmpfolder)

// Spawn Vim to edit the temporary file
cmd := exec.Command("vim", filelist)
cmd := exec.Command(*editor, filelist)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
fmt.Println("vim returned non 0. Aborting!", err)
fmt.Println("Editor returned non 0. Aborting!", err)
panic(Exit{1})
}

Expand Down

0 comments on commit 811e8b8

Please sign in to comment.