[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
@@ -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())