From 180fffa92ec7e9bc4a957be75f286f1f0d120ad6 Mon Sep 17 00:00:00 2001 From: Karel Balej Date: Tue, 15 Aug 2023 19:53:04 +0200 Subject: commands: allow reading attachments from a file Currently, aerc reads a list of files to be attached to a message from the file-picker-cmd's standard output. However, this doesn't play nice with ranger which seems to draw itself by writing there, causing it to be invisible in the embedded terminal. In fact, instead of using a pipe, aerc redirects the output of the command to a temporary file and then reads the list of files from there. Take advantage of this approach and allow user to directly reference this temporary file in the file-picker-cmd via the %f placeholder, which gets expanded to the temporary file's location. If the %f placeholder isn't present, keep the old behaviour. So for example, now it is possible to do: file-picker-cmd=ranger --choosefiles=%f in aerc.conf. Signed-off-by: Karel Balej Acked-by: Robin Jarry Reviewed-by: Tim Culverhouse --- commands/compose/attach.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'commands/compose') diff --git a/commands/compose/attach.go b/commands/compose/attach.go index 2eb8a98d..3f6d124f 100644 --- a/commands/compose/attach.go +++ b/commands/compose/attach.go @@ -154,8 +154,14 @@ func (a Attach) openMenu(aerc *widgets.Aerc, args []string) error { return err } - filepicker := exec.Command("sh", "-c", filePickerCmd+" >&3") - filepicker.ExtraFiles = append(filepicker.ExtraFiles, picks) + var filepicker *exec.Cmd + if strings.Contains(filePickerCmd, "%f") { + filePickerCmd = strings.ReplaceAll(filePickerCmd, "%f", picks.Name()) + filepicker = exec.Command("sh", "-c", filePickerCmd) + } else { + filepicker = exec.Command("sh", "-c", filePickerCmd+" >&3") + filepicker.ExtraFiles = append(filepicker.ExtraFiles, picks) + } t, err := widgets.NewTerminal(filepicker) if err != nil { -- cgit