diff options
author | Johannes Thyssen Tishman <johannes@thyssentishman.com> | 2024-03-27 17:33:49 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-04-13 21:47:44 +0200 |
commit | 9849601906f3d53e38321e4b3a4461f60520bbca (patch) | |
tree | febf9038745b312a2bb9b855be102960ab40fc0c /commands | |
parent | 569a2720ca69ce4686f5d031c0937e2c365ca5fb (diff) | |
download | aerc-9849601906f3d53e38321e4b3a4461f60520bbca.tar.gz |
pipe: allow closing the terminal automatically
Add a new -s flag to :pipe. When specified, the terminal tab opened by
the :pipe command will be automatically closed after the process is
completed instead of prompting for a key press. While this doesn't
technically silence the command (the output is not suppressed), the
output is not shown to the user.
Changelog-added: Silently close the terminal tab after piping a
message to a command with `:pipe -s <cmd>`.
Signed-off-by: Johannes Thyssen Tishman <johannes@thyssentishman.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands')
-rw-r--r-- | commands/msg/pipe.go | 3 | ||||
-rw-r--r-- | commands/util.go | 6 |
2 files changed, 7 insertions, 2 deletions
diff --git a/commands/msg/pipe.go b/commands/msg/pipe.go index 7135df01..980ba38d 100644 --- a/commands/msg/pipe.go +++ b/commands/msg/pipe.go @@ -19,6 +19,7 @@ import ( type Pipe struct { Background bool `opt:"-b"` + Silent bool `opt:"-s"` Full bool `opt:"-m"` Part bool `opt:"-p"` Command string `opt:"..."` @@ -60,7 +61,7 @@ func (p Pipe) Run(cb func()) error { doTerm := func(reader io.Reader, name string) { cmd := []string{"sh", "-c", p.Command} - term, err := commands.QuickTerm(cmd, reader) + term, err := commands.QuickTerm(cmd, reader, p.Silent) if err != nil { app.PushError(err.Error()) return diff --git a/commands/util.go b/commands/util.go index 39c9dafc..b6a458fd 100644 --- a/commands/util.go +++ b/commands/util.go @@ -23,7 +23,7 @@ import ( ) // QuickTerm is an ephemeral terminal for running a single command and quitting. -func QuickTerm(args []string, stdin io.Reader) (*app.Terminal, error) { +func QuickTerm(args []string, stdin io.Reader, silent bool) (*app.Terminal, error) { cmd := exec.Command(args[0], args[1:]...) pipe, err := cmd.StdinPipe() if err != nil { @@ -40,6 +40,10 @@ func QuickTerm(args []string, stdin io.Reader) (*app.Terminal, error) { app.PushError(err.Error()) // remove the tab on error, otherwise it gets stuck app.RemoveTab(term, false) + return + } + if silent { + app.RemoveTab(term, true) } else { app.PushStatus("Process complete, press any key to close.", 10*time.Second) |