summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-10 19:36:16 +0200
committerPaul Buetow <paul@buetow.org>2026-03-10 19:36:16 +0200
commitd1aeb4afa9afee8a0cce8827b4c2dd9f8c01fe5b (patch)
treedbe81fe676541b20741b699cbcfbc7acbd750b15 /internal
parentc43932b6eee8b8a964b9be7c21c42057f05456ba (diff)
Prefer EDITOR for stream export opener
Diffstat (limited to 'internal')
-rw-r--r--internal/tui/eventstream/export.go11
-rw-r--r--internal/tui/eventstream/export_test.go60
2 files changed, 62 insertions, 9 deletions
diff --git a/internal/tui/eventstream/export.go b/internal/tui/eventstream/export.go
index b9ddddc..f9534ff 100644
--- a/internal/tui/eventstream/export.go
+++ b/internal/tui/eventstream/export.go
@@ -138,7 +138,7 @@ func EditorCommandForPath(path string) (*exec.Cmd, error) {
}
func resolveEditorCommand() ([]string, string, error) {
- candidates := []string{"SUDO_EDITOR", "VISUAL", "EDITOR"}
+ candidates := []string{"EDITOR", "VISUAL", "SUDO_EDITOR"}
for _, key := range candidates {
value := strings.TrimSpace(os.Getenv(key))
if value == "" {
@@ -150,5 +150,12 @@ func resolveEditorCommand() ([]string, string, error) {
}
return parts, key, nil
}
- return []string{"vi"}, "fallback", nil
+ return []string{fallbackEditor()}, "fallback", nil
+}
+
+func fallbackEditor() string {
+ if _, err := exec.LookPath("hx"); err == nil {
+ return "hx"
+ }
+ return "vi"
}
diff --git a/internal/tui/eventstream/export_test.go b/internal/tui/eventstream/export_test.go
index e60e932..9bdb2d2 100644
--- a/internal/tui/eventstream/export_test.go
+++ b/internal/tui/eventstream/export_test.go
@@ -1,8 +1,12 @@
package eventstream
-import "testing"
+import (
+ "os"
+ "path/filepath"
+ "testing"
+)
-func TestResolveEditorCommandPrefersSudoEditor(t *testing.T) {
+func TestResolveEditorCommandPrefersEditor(t *testing.T) {
t.Setenv("SUDO_EDITOR", "nano")
t.Setenv("VISUAL", "vim")
t.Setenv("EDITOR", "nvim")
@@ -11,18 +15,60 @@ func TestResolveEditorCommandPrefersSudoEditor(t *testing.T) {
if err != nil {
t.Fatalf("resolve editor: %v", err)
}
- if source != "SUDO_EDITOR" {
- t.Fatalf("expected SUDO_EDITOR source, got %q", source)
+ if source != "EDITOR" {
+ t.Fatalf("expected EDITOR source, got %q", source)
}
- if len(parts) != 1 || parts[0] != "nano" {
- t.Fatalf("expected nano command, got %#v", parts)
+ if len(parts) != 1 || parts[0] != "nvim" {
+ t.Fatalf("expected nvim command, got %#v", parts)
}
}
-func TestResolveEditorCommandFallsBackToVi(t *testing.T) {
+func TestResolveEditorCommandFallsBackToVisualBeforeSudoEditor(t *testing.T) {
+ t.Setenv("SUDO_EDITOR", "nano")
+ t.Setenv("VISUAL", "vim")
+ t.Setenv("EDITOR", "")
+
+ parts, source, err := resolveEditorCommand()
+ if err != nil {
+ t.Fatalf("resolve editor: %v", err)
+ }
+ if source != "VISUAL" {
+ t.Fatalf("expected VISUAL source, got %q", source)
+ }
+ if len(parts) != 1 || parts[0] != "vim" {
+ t.Fatalf("expected vim command, got %#v", parts)
+ }
+}
+
+func TestResolveEditorCommandFallsBackToHxWhenAvailable(t *testing.T) {
+ t.Setenv("SUDO_EDITOR", "")
+ t.Setenv("VISUAL", "")
+ t.Setenv("EDITOR", "")
+
+ binDir := t.TempDir()
+ hxPath := filepath.Join(binDir, "hx")
+ if err := os.WriteFile(hxPath, []byte("#!/bin/sh\nexit 0\n"), 0o755); err != nil {
+ t.Fatalf("write hx stub: %v", err)
+ }
+ t.Setenv("PATH", binDir)
+
+ parts, source, err := resolveEditorCommand()
+ if err != nil {
+ t.Fatalf("resolve editor: %v", err)
+ }
+ if source != "fallback" {
+ t.Fatalf("expected fallback source, got %q", source)
+ }
+ if len(parts) != 1 || parts[0] != "hx" {
+ t.Fatalf("expected hx fallback, got %#v", parts)
+ }
+}
+
+func TestResolveEditorCommandFallsBackToViWhenHxMissing(t *testing.T) {
t.Setenv("SUDO_EDITOR", "")
t.Setenv("VISUAL", "")
t.Setenv("EDITOR", "")
+ t.Setenv("PATH", t.TempDir())
parts, source, err := resolveEditorCommand()
if err != nil {