~emersion/hut-dev

pager/editor: Use shlex to parse command v1 APPLIED

Thorben Günther: 1
 pager/editor: Use shlex to parse command

 4 files changed, 18 insertions(+), 2 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/hut-dev/patches/49115/mbox | git am -3
Learn more about email & git

[PATCH] pager/editor: Use shlex to parse command Export this patch

This will at least allow hut to handle flags.

References: https://todo.sr.ht/~emersion/hut/44
---
 go.mod   | 1 +
 go.sum   | 2 ++
 main.go  | 9 ++++++++-
 pager.go | 8 +++++++-
 4 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/go.mod b/go.mod
index 36e3ad9..8e34561 100644
--- a/go.mod
+++ b/go.mod
@@ -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
diff --git a/go.sum b/go.sum
index 0c3d201..5c3dbf6 100644
--- a/go.sum
+++ b/go.sum
@@ -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=
diff --git a/main.go b/main.go
index 7c05bee..487ad36 100644
--- a/main.go
+++ b/main.go
@@ -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
diff --git a/pager.go b/pager.go
index 7615f89..e6b85fd 100644
--- a/pager.go
+++ b/pager.go
@@ -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")

base-commit: c096589b7ba247f939886649c5d58b8f1cc95fd4
--
2.43.0
Pushed, thanks!