Explorar el Código

fix(config): handle editor with args on unix (#744)

Co-authored-by: Ayyan <ayn2op@gmail.com>
Abby K hace 2 meses
padre
commit
eee2862a1e

+ 11 - 0
internal/config/editor_default.go

@@ -0,0 +1,11 @@
+//go:build !unix
+
+package config
+
+import (
+	"os/exec"
+)
+
+func (cfg *Config) CreateEditorCommand(path string) *exec.Cmd {
+	return exec.Command(cfg.Editor, path)
+}

+ 11 - 0
internal/config/editor_unix.go

@@ -0,0 +1,11 @@
+//go:build unix
+
+package config
+
+import (
+	"os/exec"
+)
+
+func (cfg *Config) CreateEditorCommand(path string) *exec.Cmd {
+	return exec.Command("sh", "-c", cfg.Editor+" \"$@\"", cfg.Editor, path)
+}

+ 11 - 3
internal/ui/chat/message_input.go

@@ -2,11 +2,9 @@ package chat
 
 import (
 	"bytes"
-	"github.com/ayn2op/tview/layers"
 	"io"
 	"log/slog"
 	"os"
-	"os/exec"
 	"path/filepath"
 	"regexp"
 	"slices"
@@ -21,6 +19,7 @@ import (
 	"github.com/ayn2op/discordo/internal/consts"
 	"github.com/ayn2op/discordo/internal/ui"
 	"github.com/ayn2op/tview"
+	"github.com/ayn2op/tview/layers"
 	"github.com/diamondburned/arikawa/v3/api"
 	"github.com/diamondburned/arikawa/v3/discord"
 	"github.com/diamondburned/arikawa/v3/state"
@@ -614,7 +613,16 @@ func (mi *messageInput) editor() {
 
 	file.WriteString(mi.GetText())
 
-	cmd := exec.Command(mi.cfg.Editor, file.Name())
+	if mi.cfg.Editor == "" {
+		slog.Warn("Attempt to open file with editor, but no editor is set")
+		return
+	}
+
+	cmd := mi.cfg.CreateEditorCommand(file.Name())
+	if cmd == nil {
+		return
+	}
+
 	cmd.Stdin = os.Stdin
 	cmd.Stdout = os.Stdout
 	cmd.Stderr = os.Stderr