aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/patch/term.go26
-rw-r--r--commands/term.go29
2 files changed, 50 insertions, 5 deletions
diff --git a/commands/patch/term.go b/commands/patch/term.go
new file mode 100644
index 00000000..f2c50b15
--- /dev/null
+++ b/commands/patch/term.go
@@ -0,0 +1,26 @@
+package patch
+
+import (
+ "git.sr.ht/~rjarry/aerc/commands"
+ "git.sr.ht/~rjarry/aerc/lib/pama"
+)
+
+type Term struct {
+ Cmd []string `opt:"..." required:"false"`
+}
+
+func init() {
+ register(Term{})
+}
+
+func (Term) Aliases() []string {
+ return []string{"term"}
+}
+
+func (t Term) Execute(_ []string) error {
+ p, err := pama.New().CurrentProject()
+ if err != nil {
+ return err
+ }
+ return commands.TermCoreDirectory(t.Cmd, p.Root)
+}
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