~emersion/hut-dev

pager/editor: Invoke command with "sh -c" v2 SUPERSEDED

Thorben Günther: 1
 pager/editor: Invoke command with "sh -c"

 2 files changed, 2 insertions(+), 2 deletions(-)
Weird, it consistently fails from the command line for me. Tried both
dash and bash.

What seems to work is sh -c -- '%s "$@"' '-asdf'.
Next
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/49087/mbox | git am -3
Learn more about email & git

[PATCH v2] pager/editor: Invoke command with "sh -c" Export this patch

Closes: https://todo.sr.ht/~emersion/hut/44
---
v2: Handle leading dashes and spaces in file path

 main.go  | 2 +-
 pager.go | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/main.go b/main.go
index 7c05bee..825815a 100644
--- a/main.go
+++ b/main.go
@@ -152,7 +152,7 @@ func getInputWithEditor(pattern, initialText string) (string, error) {
		return "", err
	}

	cmd := exec.Command(editor, file.Name())
	cmd := exec.Command("sh", "-c", fmt.Sprintf("%s -- \"%s\"", editor, file.Name()))
	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
diff --git a/pager.go b/pager.go
index 7615f89..424d07b 100644
--- a/pager.go
+++ b/pager.go
@@ -24,7 +24,7 @@ func newPager() pager {
		name = "less"
	}

	cmd := exec.Command(name)
	cmd := exec.Command("sh", "-c", name)
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	cmd.Env = append(os.Environ(), "LESS=FRX")

base-commit: c096589b7ba247f939886649c5d58b8f1cc95fd4
--
2.43.0
Hm, but then this doesn't handle quotes in the filename. What I mean was
something like:

    exec.Command("sh", "-c", editor + ` "$@"`, "--", file.Name())