fix(config): handle editor with args on unix (#744)
Co-authored-by: Ayyan <ayn2op@gmail.com>
This commit is contained in:
parent
e0f1f5569a
commit
eee2862a1e
3 changed files with 33 additions and 3 deletions
11
internal/config/editor_default.go
Normal file
11
internal/config/editor_default.go
Normal 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)
|
||||
}
|
||||
11
internal/config/editor_unix.go
Normal file
11
internal/config/editor_unix.go
Normal 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)
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue