aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-09-24 21:42:59 +0200
committerRobin Jarry <robin@jarry.cc>2023-10-28 19:25:05 +0200
commit08ef572e08665ec3a06ea6ac315f3dd6d0eac5d1 (patch)
tree813338e1a727b0361cb00ccc517bc31a372a98cb
parent1db74a9ba74350776dee5f2384744357ad3aace5 (diff)
downloadaerc-08ef572e08665ec3a06ea6ac315f3dd6d0eac5d1.tar.gz
aerc-08ef572e08665ec3a06ea6ac315f3dd6d0eac5d1.zip
pipe: run commands with sh -c
Change the Cmd argument to a plain string that preserves shell quoting. Use this for sh -c instead of a list of arguments. Changelog-changed: `:pipe` commands are now executed with `sh -c`. Requested-by: Vitaly Ovchinnikov <v@postbox.nz> Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Koni Marti <koni.marti@gmail.com> Tested-by: Moritz Poldrack <moritz@poldrack.dev> Tested-by: Inwit <inwit@sindominio.net>
-rw-r--r--CHANGELOG.md1
-rw-r--r--commands/msg/pipe.go25
-rw-r--r--doc/aerc.1.scd8
3 files changed, 19 insertions, 15 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4551909e..8426331e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -36,6 +36,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- `:save -a` now works with multiple attachments with the same filename
- `:open` uses the attachment extension for temporary files, if possible
- memory leak when using notmuch with threading
+- `:pipe <cmd>` now executes `sh -c "<cmd>"` as indicated in the man page.
### Changed
diff --git a/commands/msg/pipe.go b/commands/msg/pipe.go
index 75b63b10..b984752b 100644
--- a/commands/msg/pipe.go
+++ b/commands/msg/pipe.go
@@ -7,6 +7,7 @@ import (
"os/exec"
"regexp"
"sort"
+ "strings"
"time"
"git.sr.ht/~rjarry/aerc/app"
@@ -17,10 +18,10 @@ import (
)
type Pipe struct {
- Background bool `opt:"-b"`
- Full bool `opt:"-m"`
- Part bool `opt:"-p"`
- Command []string `opt:"..."`
+ Background bool `opt:"-b"`
+ Full bool `opt:"-m"`
+ Part bool `opt:"-p"`
+ Command string `opt:"..."`
}
func init() {
@@ -39,6 +40,7 @@ func (p Pipe) Execute(args []string) error {
if p.Full && p.Part {
return errors.New("-m and -p are mutually exclusive")
}
+ name, _, _ := strings.Cut(p.Command, " ")
provider := app.SelectedTabContent().(app.ProvidesMessage)
if !p.Full && !p.Part {
@@ -53,7 +55,8 @@ func (p Pipe) Execute(args []string) error {
}
doTerm := func(reader io.Reader, name string) {
- term, err := commands.QuickTerm(p.Command, reader)
+ cmd := []string{"sh", "-c", p.Command}
+ term, err := commands.QuickTerm(cmd, reader)
if err != nil {
app.PushError(err.Error())
return
@@ -62,7 +65,7 @@ func (p Pipe) Execute(args []string) error {
}
doExec := func(reader io.Reader) {
- ecmd := exec.Command(p.Command[0], p.Command[1:]...)
+ ecmd := exec.Command("sh", "-c", p.Command)
pipe, err := ecmd.StdinPipe()
if err != nil {
return
@@ -82,11 +85,11 @@ func (p Pipe) Execute(args []string) error {
} else {
if ecmd.ProcessState.ExitCode() != 0 {
app.PushError(fmt.Sprintf(
- "%s: completed with status %d", p.Command[0],
+ "%s: completed with status %d", name,
ecmd.ProcessState.ExitCode()))
} else {
app.PushStatus(fmt.Sprintf(
- "%s: completed with status %d", p.Command[0],
+ "%s: completed with status %d", name,
ecmd.ProcessState.ExitCode()), 10*time.Second)
}
}
@@ -108,7 +111,7 @@ func (p Pipe) Execute(args []string) error {
} else {
doTerm(reader,
fmt.Sprintf("%s <%s",
- p.Command[0], title))
+ name, title))
}
})
return nil
@@ -183,7 +186,7 @@ func (p Pipe) Execute(args []string) error {
if p.Background {
doExec(reader)
} else {
- doTerm(reader, fmt.Sprintf("%s <%s", p.Command[0], title))
+ doTerm(reader, fmt.Sprintf("%s <%s", name, title))
}
}()
} else if p.Part {
@@ -200,7 +203,7 @@ func (p Pipe) Execute(args []string) error {
doExec(reader)
} else {
name := fmt.Sprintf("%s <%s/[%d]",
- p.Command[0], part.Msg.Envelope.Subject, part.Index)
+ name, part.Msg.Envelope.Subject, part.Index)
doTerm(reader, name)
}
})
diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd
index 2c49948f..2d53dca3 100644
--- a/doc/aerc.1.scd
+++ b/doc/aerc.1.scd
@@ -277,10 +277,10 @@ message list, the message in the message viewer, etc).
*-p*: Create the _<target>_ folder if it does not exist.
*:pipe* [*-bmp*] _<cmd>_
- Downloads and pipes the selected message into the given shell command, and
- opens a new terminal tab to show the result. By default, the selected
- message part is used in the message viewer and the full message is used in
- the message list.
+ Downloads and pipes the selected message into the given shell command
+ (executed with _sh -c "<cmd>"_), and opens a new terminal tab to show
+ the result. By default, the selected message part is used in the message
+ viewer and the full message is used in the message list.
Operates on multiple messages when they are marked. When piping multiple
messages, aerc will write them with mbox format separators.