diff options
author | Koni Marti <koni.marti@gmail.com> | 2023-11-24 16:03:07 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-12-30 15:42:09 +0100 |
commit | d49ed00df00b9d745a385a7b3f67832ce147380d (patch) | |
tree | 4ecf2dc604790aadc027a36479f3cce36cfe777c /commands/term.go | |
parent | 6592d6e711a2d909465a758259adc76edc5ae3e6 (diff) | |
download | aerc-d49ed00df00b9d745a385a7b3f67832ce147380d.tar.gz |
patch/term: add term sub-cmd
Implement the :patch term command. This will open a shell in the
project's root directory that was defined during the :project init
setup.
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands/term.go')
-rw-r--r-- | commands/term.go | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/commands/term.go b/commands/term.go index 3f8f9875..d115cd25 100644 --- a/commands/term.go +++ b/commands/term.go @@ -1,6 +1,7 @@ package commands import ( + "os" "os/exec" "github.com/riywo/loginshell" @@ -22,21 +23,39 @@ func (Term) Aliases() []string { } func (t Term) Execute(args []string) error { - if len(t.Cmd) == 0 { + 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 } - t.Cmd = []string{shell} + args = []string{shell} } - term, err := app.NewTerminal(exec.Command(t.Cmd[0], t.Cmd[1:]...)) + + 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 } - tab := app.NewTab(term, t.Cmd[0]) + tab := app.NewTab(term, args[0]) term.OnTitle = func(title string) { if title == "" { - title = t.Cmd[0] + title = args[0] } if tab.Name != title { tab.Name = title |