aboutsummaryrefslogtreecommitdiff
path: root/commands
diff options
context:
space:
mode:
authorJeffas <dev@jeffas.io>2019-07-19 18:12:57 +0100
committerDrew DeVault <sir@cmpwn.com>2019-07-23 10:27:59 -0400
commite42b95a617399b2736df96ae6469309e6b306d71 (patch)
tree65bd6f78faa0607a3d73a35b7c59a713472adbea /commands
parentd526786c9358bc92a5ffc3233e0ba4491aff07ba (diff)
Add change tab command
This command allows the user to change tab by giving the tab name. This can be tab completed too. The previous tab is stored in the tabs module so that when a new tab is created it is still possible to go to the previous one. Normal invocation is :ct folder Previous tab is :ct -
Diffstat (limited to 'commands')
-rw-r--r--commands/ct.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/commands/ct.go b/commands/ct.go
new file mode 100644
index 0000000..ab2993d
--- /dev/null
+++ b/commands/ct.go
@@ -0,0 +1,48 @@
+package commands
+
+import (
+ "errors"
+ "fmt"
+ "strings"
+
+ "git.sr.ht/~sircmpwn/aerc/widgets"
+)
+
+type ChangeTab struct{}
+
+func init() {
+ register(ChangeTab{})
+}
+
+func (_ ChangeTab) Aliases() []string {
+ return []string{"ct", "change-tab"}
+}
+
+func (_ ChangeTab) Complete(aerc *widgets.Aerc, args []string) []string {
+ out := make([]string, 0)
+ for _, tab := range aerc.TabNames() {
+ if strings.HasPrefix(tab, args[0]) {
+ out = append(out, tab)
+ }
+ }
+ return out
+}
+
+func (_ ChangeTab) Execute(aerc *widgets.Aerc, args []string) error {
+ if len(args) != 2 {
+ return errors.New(fmt.Sprintf("Usage: %s <tab>", args[0]))
+ }
+
+ if args[1] == "-" {
+ ok := aerc.SelectPreviousTab()
+ if !ok {
+ return errors.New("No previous tab to return to")
+ }
+ } else {
+ ok := aerc.SelectTab(args[1])
+ if !ok {
+ return errors.New("No tab with that name")
+ }
+ }
+ return nil
+}