diff options
Diffstat (limited to 'commands/msg/pipe.go')
-rw-r--r-- | commands/msg/pipe.go | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/commands/msg/pipe.go b/commands/msg/pipe.go index d37ab0ff..e972b133 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/commands" @@ -17,10 +18,10 @@ import ( ) type Pipe struct { - Background bool `opt:"-b"` - Full bool `opt:"-m"` - Part bool `opt:"-p"` - Cmd []string `opt:"..."` + Background bool `opt:"-b"` + Full bool `opt:"-m"` + Part bool `opt:"-p"` + Cmd string `opt:"..."` } func init() { @@ -39,6 +40,7 @@ func (p Pipe) Execute(aerc *widgets.Aerc, args []string) error { if p.Full && p.Part { return errors.New("-m and -p are mutually exclusive") } + name, _, _ := strings.Cut(p.Cmd, " ") provider := aerc.SelectedTabContent().(widgets.ProvidesMessage) if !p.Full && !p.Part { @@ -53,7 +55,8 @@ func (p Pipe) Execute(aerc *widgets.Aerc, args []string) error { } doTerm := func(reader io.Reader, name string) { - term, err := commands.QuickTerm(aerc, p.Cmd, reader) + cmd := []string{"sh", "-c", p.Cmd} + term, err := commands.QuickTerm(aerc, cmd, reader) if err != nil { aerc.PushError(err.Error()) return @@ -62,7 +65,7 @@ func (p Pipe) Execute(aerc *widgets.Aerc, args []string) error { } doExec := func(reader io.Reader) { - ecmd := exec.Command(p.Cmd[0], p.Cmd[1:]...) + ecmd := exec.Command("sh", "-c", p.Cmd) pipe, err := ecmd.StdinPipe() if err != nil { return @@ -82,11 +85,11 @@ func (p Pipe) Execute(aerc *widgets.Aerc, args []string) error { } else { if ecmd.ProcessState.ExitCode() != 0 { aerc.PushError(fmt.Sprintf( - "%s: completed with status %d", p.Cmd[0], + "%s: completed with status %d", name, ecmd.ProcessState.ExitCode())) } else { aerc.PushStatus(fmt.Sprintf( - "%s: completed with status %d", p.Cmd[0], + "%s: completed with status %d", name, ecmd.ProcessState.ExitCode()), 10*time.Second) } } @@ -106,7 +109,7 @@ func (p Pipe) Execute(aerc *widgets.Aerc, args []string) error { } else { doTerm(reader, fmt.Sprintf("%s <%s", - p.Cmd[0], title)) + name, title)) } }) return nil @@ -181,7 +184,7 @@ func (p Pipe) Execute(aerc *widgets.Aerc, args []string) error { if p.Background { doExec(reader) } else { - doTerm(reader, fmt.Sprintf("%s <%s", p.Cmd[0], title)) + doTerm(reader, fmt.Sprintf("%s <%s", name, title)) } }() } else if p.Part { @@ -198,7 +201,7 @@ func (p Pipe) Execute(aerc *widgets.Aerc, args []string) error { doExec(reader) } else { name := fmt.Sprintf("%s <%s/[%d]", - p.Cmd[0], part.Msg.Envelope.Subject, part.Index) + name, part.Msg.Envelope.Subject, part.Index) doTerm(reader, name) } }) |