diff --git a/cmd/mmv/main.go b/cmd/mmv/main.go index 0fe5d51..3eb21e0 100644 --- a/cmd/mmv/main.go +++ b/cmd/mmv/main.go @@ -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() diff --git a/go.mod b/go.mod index ef090f5..f7b9d35 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/itchyny/mmv go 1.20 require ( + github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/mattn/getwild v0.0.2-0.20200919000855-c2e221927ad6 github.com/mattn/go-tty v0.0.4 ) diff --git a/go.sum b/go.sum index a384a42..2933528 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= +github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= github.com/mattn/getwild v0.0.2-0.20200919000855-c2e221927ad6 h1:uWR+2CTTaHQzDS/DApbJ2H8UEPQl90atrKtczXj2xcs= github.com/mattn/getwild v0.0.2-0.20200919000855-c2e221927ad6/go.mod h1:AG+GKQydHp7iLJn+VV+D7y8LeYs5bQ0Xz4fmKd5o1Sg= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=