~rjarry/aerc-devel

aerc: pipe: expanding "~" in its "command" parameter v1 NEEDS REVISION

Robin Jarry: 1
 pipe: expanding "~" in its "command" parameter
Vitaly Ovchinnikov: 1
 pipe: expanding "~" in its "command" parameter

 2 files changed, 13 insertions(+), 6 deletions(-)
#1058449 alpine-edge.yml success
#1058450 openbsd.yml success
Vitaly Ovchinnikov, Sep 19, 2023 at 14:08:
Next
Vitaly Ovchinnikov, Sep 19, 2023 at 14:37:
Next
Vitaly Ovchinnikov, Sep 19, 2023 at 18:56:
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/~rjarry/aerc-devel/patches/44797/mbox | git am -3
Learn more about email & git

[PATCH aerc] pipe: expanding "~" in its "command" parameter Export this patch

Add expanding of home directory symbol (~) in the "command" parameter
of ":pipe" command.

Signed-off-by: Vitaly Ovchinnikov <v@postbox.nz>
---
Good for piping stuff to local aerc-specific helpers that are not in the
paths. Here's a sample binding I need:

o = :pipe -b ~/.config/aerc/helpers/do-stuff<Enter>

Instead I have to put the absolute file name of the helper there. The
patch fixes that.
 commands/msg/pipe.go | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/commands/msg/pipe.go b/commands/msg/pipe.go
index fc1ac8f..7cb2378 100644
--- a/commands/msg/pipe.go
+++ b/commands/msg/pipe.go
@@ -10,6 +10,7 @@ import (
	"time"

	"git.sr.ht/~rjarry/aerc/commands"
	"git.sr.ht/~rjarry/aerc/lib/xdg"
	"git.sr.ht/~rjarry/aerc/log"
	"git.sr.ht/~rjarry/aerc/widgets"
	mboxer "git.sr.ht/~rjarry/aerc/worker/mbox"
@@ -64,6 +65,8 @@ func (Pipe) Execute(aerc *widgets.Aerc, args []string) error {
		return errors.New("Usage: pipe [-mp] <cmd> [args...]")
	}

	cmd[0] = xdg.ExpandHome(cmd[0])

	provider := aerc.SelectedTabContent().(widgets.ProvidesMessage)
	if !pipeFull && !pipePart {
		if _, ok := provider.(*widgets.MessageViewer); ok {
-- 
2.39.2 (Apple Git-143)
aerc/patches: SUCCESS in 5m59s

[pipe: expanding "~" in its "command" parameter][0] from [Vitaly Ovchinnikov][1]

[0]: https://lists.sr.ht/~rjarry/aerc-devel/patches/44797
[1]: mailto:v@postbox.nz

✓ #1058450 SUCCESS aerc/patches/openbsd.yml     https://builds.sr.ht/~rjarry/job/1058450
✓ #1058449 SUCCESS aerc/patches/alpine-edge.yml https://builds.sr.ht/~rjarry/job/1058449

Re: [PATCH aerc] pipe: expanding "~" in its "command" parameter Export this patch

Vitaly Ovchinnikov, Sep 16, 2023 at 18:47:
> Add expanding of home directory symbol (~) in the "command" parameter
> of ":pipe" command.
>
> Signed-off-by: Vitaly Ovchinnikov <v@postbox.nz>
> ---
> Good for piping stuff to local aerc-specific helpers that are not in the
> paths. Here's a sample binding I need:
>
> o = :pipe -b ~/.config/aerc/helpers/do-stuff<Enter>
>
> Instead I have to put the absolute file name of the helper there. The
> patch fixes that.

This is nice but a bit limited since it only expands for the first
argument.

I would prefer if the command could be a shell command. That way you'd
get ~ expansion anywhere in the command and you could chain pipes with
other commands as well.

    :pipe -m foo -C ~/tmp xyz | tr '\n' ' ' | tac

Filter commands already work that way and the man page already mentions
that :pipe takes a *shell* command. The patch should look something like
this:
diff --git a/commands/msg/pipe.go b/commands/msg/pipe.go
index fc1ac8f8693a..20dbfb4fa27e 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"
@@ -61,9 +62,12 @@ func (Pipe) Execute(aerc *widgets.Aerc, args []string) error {
       }
       cmd := args[optind:]
       if len(cmd) == 0 {
               return errors.New("Usage: pipe [-mp] <cmd> [args...]")
               return errors.New("Usage: pipe [-bmp] <cmd> [args...]")
       }

       name := cmd[0]
       cmd = []string{"sh", "-c", strings.Join(cmd, " ")}

       provider := aerc.SelectedTabContent().(widgets.ProvidesMessage)
       if !pipeFull && !pipePart {
               if _, ok := provider.(*widgets.MessageViewer); ok {
@@ -106,11 +110,11 @@ func (Pipe) Execute(aerc *widgets.Aerc, args []string) error {
               } else {
                       if ecmd.ProcessState.ExitCode() != 0 {
                               aerc.PushError(fmt.Sprintf(
                                       "%s: completed with status %d", cmd[0],
                                       "%s: completed with status %d", name,
                                       ecmd.ProcessState.ExitCode()))
                       } else {
                               aerc.PushStatus(fmt.Sprintf(
                                       "%s: completed with status %d", cmd[0],
                                       "%s: completed with status %d", name,
                                       ecmd.ProcessState.ExitCode()), 10*time.Second)
                       }
               }
@@ -130,7 +134,7 @@ func (Pipe) Execute(aerc *widgets.Aerc, args []string) error {
                                       } else {
                                               doTerm(reader,
                                                       fmt.Sprintf("%s <%s",
                                                               cmd[0], title))
                                                               name, title))
                                       }
                               })
                               return nil
@@ -205,7 +209,7 @@ func (Pipe) Execute(aerc *widgets.Aerc, args []string) error {
                       if background {
                               doExec(reader)
                       } else {
                               doTerm(reader, fmt.Sprintf("%s <%s", cmd[0], title))
                               doTerm(reader, fmt.Sprintf("%s <%s", name, title))
                       }
               }()
       } else if pipePart {
@@ -222,7 +226,7 @@ func (Pipe) Execute(aerc *widgets.Aerc, args []string) error {
                               doExec(reader)
                       } else {
                               name := fmt.Sprintf("%s <%s/[%d]",
                                       cmd[0], p.Msg.Envelope.Subject, p.Index)
                                       name, p.Msg.Envelope.Subject, p.Index)
                               doTerm(reader, name)
                       }
               })