From 8db595128754d6133de3f82c60d3adea1ef77c26 Mon Sep 17 00:00:00 2001 From: Affaan Mustafa Date: Tue, 21 Oct 2025 18:49:42 -0700 Subject: feat: Improve editor detection with auto-discovery and better error messages (#3155) Co-authored-by: opencode-agent[bot] Co-authored-by: rekram1-node --- packages/tui/internal/util/util.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'packages/tui/internal/util') diff --git a/packages/tui/internal/util/util.go b/packages/tui/internal/util/util.go index fdefb2901..b49d2e292 100644 --- a/packages/tui/internal/util/util.go +++ b/packages/tui/internal/util/util.go @@ -3,6 +3,8 @@ package util import ( "log/slog" "os" + "os/exec" + "runtime" "strings" "time" @@ -45,3 +47,25 @@ func Measure(tag string) func(...any) { slog.Debug(tag, args...) } } + +func GetEditor() string { + if editor := os.Getenv("VISUAL"); editor != "" { + return editor + } + if editor := os.Getenv("EDITOR"); editor != "" { + return editor + } + + commonEditors := []string{"vim", "nvim", "zed", "code", "cursor", "vi", "nano"} + if runtime.GOOS == "windows" { + commonEditors = []string{"vim", "nvim", "zed", "code.cmd", "cursor.cmd", "notepad.exe", "vi", "nano"} + } + + for _, editor := range commonEditors { + if _, err := exec.LookPath(editor); err == nil { + return editor + } + } + + return "" +} -- cgit v1.2.3