Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions internal/app/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"

tea "github.com/charmbracelet/bubbletea"

Expand Down Expand Up @@ -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}
})
Expand Down
Loading