diff --git a/internal/config/editor_default.go b/internal/config/editor_default.go new file mode 100644 index 0000000..0e20f03 --- /dev/null +++ b/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) +} diff --git a/internal/config/editor_unix.go b/internal/config/editor_unix.go new file mode 100644 index 0000000..cec488a --- /dev/null +++ b/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) +} diff --git a/internal/ui/chat/message_input.go b/internal/ui/chat/message_input.go index f5093ab..facbaee 100644 --- a/internal/ui/chat/message_input.go +++ b/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