Files
aerc-fork-mirror/commands/term.go
Karel Balej 5919e9dfda term: allow setting custom title for the terminal tab
Add a template for the terminal tab title and define two
terminal-specific properties: Title which expands to whatever the
underlying application requests via OSC and defaults to the command name
and Bell which is a boolean indicating whether the application has
emitted bell, the flag is cleared when the corresponding tab gains focus
and is not set at all if it currently has it.

This can among other things be used to highlight the terminal tab when
the underlying process prints the bell, such as by setting the template
as such:

	tab-title-terminal={{if .Bell}}[BELL] {{end}}{{.Title}}

Implements: https://todo.sr.ht/~rjarry/aerc/138
Changelog-added: A tab-title-terminal setting for customizing the
 title of tabs in which the terminal widget is run.
Requested-by: Drew DeVault <drew@ddevault.org>
Signed-off-by: Karel Balej <balejk@matfyz.cz>
Acked-by: Robin Jarry <robin@jarry.cc>
2025-05-05 13:49:04 +02:00

73 lines
1.2 KiB
Go

package commands
import (
"os"
"os/exec"
"github.com/riywo/loginshell"
"git.sr.ht/~rjarry/aerc/app"
)
type Term struct {
Cmd []string `opt:"..." required:"false"`
}
func init() {
Register(Term{})
}
func (Term) Description() string {
return "Open a new terminal tab."
}
func (Term) Context() CommandContext {
return GLOBAL
}
func (Term) Aliases() []string {
return []string{"terminal", "term"}
}
func (t Term) Execute(args []string) error {
return TermCore(t.Cmd)
}
// The help command is an alias for `term man` thus Term requires a simple func
func TermCore(args []string) error {
return TermCoreDirectory(args, "")
}
func TermCoreDirectory(args []string, dir string) error {
if len(args) == 0 {
shell, err := loginshell.Shell()
if err != nil {
return err
}
args = []string{shell}
}
if dir != "" {
if _, err := os.Stat(dir); os.IsNotExist(err) {
return err
}
}
cmd := exec.Command(args[0], args[1:]...)
cmd.Dir = dir
term, err := app.NewTerminal(cmd)
if err != nil {
return err
}
title := term.RenderTitle()
tab := app.NewTab(term, title)
term.SetTab(tab)
term.OnClose = func(err error) {
app.RemoveTab(term, false)
if err != nil {
app.PushError(err.Error())
}
}
return nil
}