on main help sign in
fix(editor): fix opening `$EDITOR` w/ and w/o args (#1520)
commit4f37cff65d79273b67faa83b1b1f78a69b8fddaa authorAmolith <amolith@secluded.site> dateMon 1 Dec 2025, 06:40 (1 year ago) parente5639f0
2 files changed+28−6
internal/tui/components/chat/editor/editor.go+2−6 internal/tui/util/shell.go+26
internal/tui/components/chat/editor/editor.go+2−6
@@ -6,7 +6,6 @@ import (
66 "math/rand"
77 "net/http"
88 "os"
9− "os/exec"
109 "path/filepath"
1110 "runtime"
1211 "slices"
@@ -112,11 +111,8 @@ func (m *editorCmp) openEditor(value string) tea.Cmd {
112111 if _, err := tmpfile.WriteString(value); err != nil {
113112 return util.ReportError(err)
114113 }
115− c := exec.CommandContext(context.TODO(), editor, tmpfile.Name())
116− c.Stdin = os.Stdin
117− c.Stdout = os.Stdout
118− c.Stderr = os.Stderr
119− return tea.ExecProcess(c, func(err error) tea.Msg {
114+ cmdStr := editor + " " + tmpfile.Name()
115+ return util.ExecShell(context.TODO(), cmdStr, func(err error) tea.Msg {
120116 if err != nil {
121117 return util.ReportError(err)
122118 }
internal/tui/util/shell.gonew file+26
@@ -0,0 +1,26 @@
1+package util
2+
3+import (
4+ "context"
5+ "errors"
6+ "os/exec"
7+
8+ tea "charm.land/bubbletea/v2"
9+ "mvdan.cc/sh/v3/shell"
10+)
11+
12+// ExecShell parses a shell command string and executes it with exec.Command.
13+// Uses shell.Fields for proper handling of shell syntax like quotes and
14+// arguments while preserving TTY handling for terminal editors.
15+func ExecShell(ctx context.Context, cmdStr string, callback tea.ExecCallback) tea.Cmd {
16+ fields, err := shell.Fields(cmdStr, nil)
17+ if err != nil {
18+ return ReportError(err)
19+ }
20+ if len(fields) == 0 {
21+ return ReportError(errors.New("empty command"))
22+ }
23+
24+ cmd := exec.CommandContext(ctx, fields[0], fields[1:]...)
25+ return tea.ExecProcess(cmd, callback)
26+}