diff options
| author | Affaan Mustafa <[email protected]> | 2025-10-21 18:49:42 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-10-21 20:49:42 -0500 |
| commit | 8db595128754d6133de3f82c60d3adea1ef77c26 (patch) | |
| tree | c3008b9f3850c00367196de788ee5ef1d4cba4cc /packages/tui/internal/util | |
| parent | 97c7e941eb864fa4db2a94919a924f47ee002346 (diff) | |
| download | opencode-8db595128754d6133de3f82c60d3adea1ef77c26.tar.gz opencode-8db595128754d6133de3f82c60d3adea1ef77c26.zip | |
feat: Improve editor detection with auto-discovery and better error messages (#3155)
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Co-authored-by: rekram1-node <[email protected]>
Diffstat (limited to 'packages/tui/internal/util')
| -rw-r--r-- | packages/tui/internal/util/util.go | 24 |
1 files changed, 24 insertions, 0 deletions
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 "" +} |
