mirror of
https://github.com/itchyny/mmv.git
synced 2025-12-30 09:11:34 +08:00
split EDITOR in Go to remove dependency on sh (ref #19)
This commit is contained in:
parent
f627dff093
commit
7c8adbbb4c
3 changed files with 15 additions and 1 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/kballard/go-shellquote"
|
||||
_ "github.com/mattn/getwild"
|
||||
"github.com/mattn/go-tty"
|
||||
|
||||
|
|
@ -98,7 +99,17 @@ func rename(args []string) error {
|
|||
}
|
||||
defer tty.Close()
|
||||
|
||||
cmd := exec.Command("sh", "-c", `eval exec "${EDITOR:-vi}" '"$@"'`, "", f.Name())
|
||||
editor := os.Getenv("EDITOR")
|
||||
if editor == "" {
|
||||
editor = "vi"
|
||||
}
|
||||
editorWithArgs, err := shellquote.Split(editor)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %s", err, editor)
|
||||
}
|
||||
editorWithArgs = append(editorWithArgs, f.Name())
|
||||
|
||||
cmd := exec.Command(editorWithArgs[0], editorWithArgs[1:]...)
|
||||
cmd.Stdin = tty.Input()
|
||||
cmd.Stdout = tty.Output()
|
||||
cmd.Stderr = tty.Output()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue