From 77e325abbb4bc581c1dcc358ac288411b49f9d7a Mon Sep 17 00:00:00 2001 From: turnipy Date: Mon, 6 Apr 2026 12:18:46 +1000 Subject: [PATCH 1/2] Add view_mode config option to open files with system default viewer Adds a `view_mode` setting under `[behavior]` in config.toml. When set to `"system"`, pressing F3 (View) opens the file using the OS default application (xdg-open on Linux, open on macOS, explorer on Windows) instead of the terminal pager. Useful for images, videos, PDFs, and other binary/non-text formats. Defaults to `"pager"` for unchanged backward-compatible behaviour. Co-Authored-By: Claude Sonnet 4.6 --- internal/app/app.go | 6 +++++- internal/app/commands.go | 17 +++++++++++++++++ internal/config/config.go | 6 ++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/internal/app/app.go b/internal/app/app.go index 7d8b086..93fa509 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -675,7 +675,11 @@ func (m Model) startView() (tea.Model, tea.Cmd) { if e == nil || e.IsDir() { return m, nil } - return m, viewFileCmd(m.currentFilePath()) + path := m.currentFilePath() + if m.cfg.Behavior.ViewMode == "system" { + return m, openSystemDefaultCmd(path) + } + return m, viewFileCmd(path) } func (m Model) startEdit() (tea.Model, tea.Cmd) { diff --git a/internal/app/commands.go b/internal/app/commands.go index 439676f..a7cf2ef 100644 --- a/internal/app/commands.go +++ b/internal/app/commands.go @@ -4,6 +4,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" tea "github.com/charmbracelet/bubbletea" @@ -67,6 +68,22 @@ func viewFileCmd(path string) tea.Cmd { }) } +func openSystemDefaultCmd(path string) tea.Cmd { + return func() tea.Msg { + var c *exec.Cmd + switch runtime.GOOS { + case "darwin": + c = exec.Command("open", path) + case "windows": + c = exec.Command("explorer", path) + default: + c = exec.Command("xdg-open", path) + } + _ = c.Start() + return externalDoneMsg{} + } +} + func editFileCmd(path string) tea.Cmd { editor := os.Getenv("EDITOR") if editor == "" { diff --git a/internal/config/config.go b/internal/config/config.go index 9db7825..7ebc037 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -24,6 +24,8 @@ type BehaviorConfig struct { EnterAction string `toml:"enter_action"` // What Space does on a file: "preview" (default) or "edit" SpaceAction string `toml:"space_action"` + // ViewMode controls how F3 opens files: "pager" (default, uses $PAGER/less) or "system" (OS default app) + ViewMode string `toml:"view_mode"` } // KeyBindings defines all configurable key bindings. @@ -93,6 +95,7 @@ func Default() Config { Behavior: BehaviorConfig{ EnterAction: "edit", SpaceAction: "preview", + ViewMode: "pager", }, Keys: keys, } @@ -161,6 +164,9 @@ func Load() Config { if fileCfg.Behavior.SpaceAction != "" { cfg.Behavior.SpaceAction = fileCfg.Behavior.SpaceAction } + if fileCfg.Behavior.ViewMode != "" { + cfg.Behavior.ViewMode = fileCfg.Behavior.ViewMode + } mergeKeys(&cfg.Keys, &fileCfg.Keys) normalizeAllKeys(&cfg.Keys) From 6961239bf07d5e50ab9aed085e02db3e27e13522 Mon Sep 17 00:00:00 2001 From: turnipy Date: Mon, 6 Apr 2026 12:20:54 +1000 Subject: [PATCH 2/2] Fix space_action not honouring view_mode setting fileActionCmd's "preview" case called viewFileCmd directly, bypassing the view_mode config. Now routes through openSystemDefaultCmd when view_mode = "system", consistent with the F3 View behaviour. Co-Authored-By: Claude Sonnet 4.6 --- internal/app/app.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/app/app.go b/internal/app/app.go index 93fa509..9313351 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -557,6 +557,9 @@ func (m *Model) fileActionCmd(path string, action string) tea.Cmd { case "edit": return editFileCmd(path) case "preview": + if m.cfg.Behavior.ViewMode == "system" { + return openSystemDefaultCmd(path) + } return viewFileCmd(path) default: return editFileCmd(path)