~emersion/hut

6c85e1e3726a54e10783db84d72e0eafa1428090 — Thorben G√ľnther 2 months ago 5dce3a9 master
pager/editor: Use shlex to parse command

This will at least allow hut to handle flags.

References: https://todo.sr.ht/~emersion/hut/44
4 files changed, 18 insertions(+), 2 deletions(-)

M go.mod
M go.sum
M main.go
M pager.go
M go.mod => go.mod +1 -0
@@ 6,6 6,7 @@ require (
	git.sr.ht/~emersion/go-scfg v0.0.0-20231211181832-0b4e72d8ec3c
	git.sr.ht/~emersion/gqlclient v0.0.0-20230820050442-8873fe0204b9
	github.com/dustin/go-humanize v1.0.1
	github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
	github.com/juju/ansiterm v1.0.0
	github.com/spf13/cobra v1.8.0
	golang.org/x/term v0.14.0

M go.sum => go.sum +2 -0
@@ 18,6 18,8 @@ github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48 h1:fRzb/w+pyskVMQ+
github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/juju/ansiterm v1.0.0 h1:gmMvnZRq7JZJx6jkfSq9/+2LMrVEwGwt7UR6G+lmDEg=

M main.go => main.go +8 -1
@@ 15,6 15,7 @@ import (
	"unicode"

	"git.sr.ht/~emersion/hut/termfmt"
	"github.com/google/shlex"
	"github.com/spf13/cobra"
)



@@ 134,6 135,11 @@ func getInputWithEditor(pattern, initialText string) (string, error) {
		return "", errors.New("EDITOR not set")
	}

	commandSplit, err := shlex.Split(editor)
	if err != nil {
		return "", err
	}

	file, err := os.CreateTemp("", pattern)
	if err != nil {
		return "", err


@@ 152,7 158,8 @@ func getInputWithEditor(pattern, initialText string) (string, error) {
		return "", err
	}

	cmd := exec.Command(editor, file.Name())
	commandSplit = append(commandSplit, file.Name())
	cmd := exec.Command(commandSplit[0], commandSplit[1:]...)
	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr

M pager.go => pager.go +7 -1
@@ 7,6 7,7 @@ import (
	"os/exec"

	"git.sr.ht/~emersion/hut/termfmt"
	"github.com/google/shlex"
)

type pager interface {


@@ 24,7 25,12 @@ func newPager() pager {
		name = "less"
	}

	cmd := exec.Command(name)
	commandSplit, err := shlex.Split(name)
	if err != nil {
		log.Fatalf("Failed to parse pager command: %v", err)
	}

	cmd := exec.Command(commandSplit[0], commandSplit[1:]...)
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	cmd.Env = append(os.Environ(), "LESS=FRX")