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

Co-authored-by: Ayyan <ayn2op@gmail.com>
This commit is contained in:
Abby K 2026-02-17 01:33:49 -05:00 • committed by GitHub
parent e0f1f5569a
commit eee2862a1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 33 additions and 3 deletions

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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