From e05b812a772e9bba6ce0f5944a9fd46a1c8f5a82 Mon Sep 17 00:00:00 2001 From: Csaba Endre Simon Date: Fri, 3 Apr 2026 17:55:43 +0200 Subject: [PATCH] fix view/edit commands to support multi-word PAGER/EDITOR values Consolidate viewFileCmd and editFileCmd into a shared externalCmd helper that splits the env var with strings.Fields, so commands like EDITOR="code --wait" work correctly. --- internal/app/commands.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/internal/app/commands.go b/internal/app/commands.go index 439676f..3fa26fc 100644 --- a/internal/app/commands.go +++ b/internal/app/commands.go @@ -4,6 +4,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" tea "github.com/charmbracelet/bubbletea" @@ -57,22 +58,20 @@ func renameCmd(oldPath, newName string) tea.Cmd { } func viewFileCmd(path string) tea.Cmd { - pager := os.Getenv("PAGER") - if pager == "" { - pager = "less" - } - c := exec.Command(pager, path) - return tea.ExecProcess(c, func(err error) tea.Msg { - return externalDoneMsg{err: err} - }) + return externalCmd("PAGER", "less", path) } func editFileCmd(path string) tea.Cmd { - editor := os.Getenv("EDITOR") - if editor == "" { - editor = "vi" + return externalCmd("EDITOR", "vi", path) +} + +func externalCmd(envVar, fallback, path string) tea.Cmd { + cmd := strings.TrimSpace(os.Getenv(envVar)) + if cmd == "" { + cmd = fallback } - c := exec.Command(editor, path) + parts := strings.Fields(cmd) + c := exec.Command(parts[0], append(parts[1:], path)...) return tea.ExecProcess(c, func(err error) tea.Msg { return externalDoneMsg{err: err} })