~sircmpwn/aerc

Adds FIFO support v2 PROPOSED

Sebastian
Sebastian: 1
 Adds FIFO support

 2 files changed, 43 insertions(+), 1 deletions(-)
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/~sircmpwn/aerc/patches/21597/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH v2] Adds FIFO support Export this patch

Sebastian
This commit give aerc the ability to read commands through a FIFO
(named pipe). A command line flag is added (`-f`) which specifies the
path of the FIFO to read commands from. If no -f option is specified,
aerc doesn't read from any FIFO.
---
 aerc.go         | 22 +++++++++++++++++++++-
 widgets/aerc.go | 22 ++++++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/aerc.go b/aerc.go
index 33acb43..573931d 100644
--- a/aerc.go
+++ b/aerc.go
@@ -95,14 +95,17 @@ func usage() {
}

func main() {
	opts, optind, err := getopt.Getopts(os.Args, "v")
	opts, optind, err := getopt.Getopts(os.Args, "f:v")
	if err != nil {
		log.Print(err)
		usage()
		return
	}
	fifopath := ""
	for _, opt := range opts {
		switch opt.Option {
		case 'f':
			fifopath = opt.Value
		case 'v':
			fmt.Println("aerc " + Version)
			return
@@ -162,6 +165,23 @@ func main() {
		return getCompletions(aerc, cmd)
	}, &commands.CmdHistory)

	if len(fifopath) > 0 {
		// check that fifo exists
		fileinfo, err := os.Stat(fifopath)
		if err != nil && os.IsNotExist(err) {
			fmt.Fprintf(os.Stderr, "Fatal: Provided FIFO path doesn't exist\n")
			os.Exit(1)
		} else if err != nil {
			fmt.Fprintf(os.Stderr, "Fatal: Error getting FIFO status: %v\n", err)
			os.Exit(1)
		} else if fileinfo.Mode() & os.ModeNamedPipe == 0 {
			fmt.Fprintf(os.Stderr, "Fatal: File isn't a FIFO\n")
			os.Exit(1)
		}

		go aerc.ListenFifo(fifopath)
	}

	ui, err = libui.Initialize(aerc)
	if err != nil {
		panic(err)
diff --git a/widgets/aerc.go b/widgets/aerc.go
index 6df0c95..3b92ebe 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -4,6 +4,7 @@ import (
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"net/url"
	"strings"
@@ -424,6 +425,27 @@ func (aerc *Aerc) focus(item ui.Interactive) {
	}
}

func (aerc *Aerc) ListenFifo(fifopath string) {
	// read+exec loop
	for {
		data, err := ioutil.ReadFile(fifopath)
		if err != nil {
			aerc.PushError(err.Error())
			continue
		}

		cmd := string(data)
		parts, err := shlex.Split(cmd)
		if err != nil {
			aerc.PushError(err.Error())
		}
		err = aerc.cmd(parts)
		if err != nil {
			aerc.PushError(err.Error())
		}
	}
}

func (aerc *Aerc) BeginExCommand(cmd string) {
	previous := aerc.focused
	exline := NewExLine(aerc.conf, cmd, func(cmd string) {
-- 
2.31.0
Hi Sebastian,

On Mon, Mar 29, 2021 at 01:51:12PM -0400, Sebastian wrote: