Skip to content

Commit 0b127cd

Browse files
stefan-fastStefan Fast
andauthored
fix: Error when using EDITOR environment variable with arguments (#44)
* Read arguments of command in EDITOR env variable and pass them * fix: Improved solution by making use of strings.Fields Co-authored-by: Stefan Fast <[email protected]>
1 parent e653a53 commit 0b127cd

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

internal/cmd/edit.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package cmd
22

33
import (
44
"fmt"
5-
"log"
65
"os"
76
"os/exec"
87
"path/filepath"
8+
"strings"
99
"time"
1010

1111
"github.com/spf13/cobra"
@@ -28,13 +28,19 @@ func newEditCmd() *editCmd {
2828
return err
2929
}
3030

31-
editor := os.Getenv("EDITOR")
32-
if editor == "" {
31+
editor := strings.Fields(os.Getenv("EDITOR"))
32+
if len(editor) == 0 {
3333
return fmt.Errorf("no $EDITOR set")
3434
}
3535

36-
log.Printf("%s %s\n", editor, tmp)
37-
edit := exec.Command(editor, tmp)
36+
editorCmd := editor[0]
37+
var editorArgs []string
38+
if len(editor) > 1 {
39+
editorArgs = append(editorArgs, editor[1:]...)
40+
}
41+
editorArgs = append(editorArgs, tmp)
42+
43+
edit := exec.Command(editorCmd, editorArgs...)
3844
edit.Stderr = os.Stderr
3945
edit.Stdout = os.Stdout
4046
edit.Stdin = os.Stdin

0 commit comments

Comments
 (0)