M commands/ct.go => commands/ct.go +23 -4
@@ 3,6 3,7 @@ package commands
import (
"errors"
"fmt"
+ "strconv"
"strings"
"git.sr.ht/~sircmpwn/aerc/widgets"
@@ 35,16 36,34 @@ 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")
+ n, err := strconv.Atoi(args[1])
+ if err == nil {
+ if strings.HasPrefix(args[1], "+") {
+ for ; n > 0; n-- {
+ aerc.NextTab()
+ }
+ } else if strings.HasPrefix(args[1], "-") {
+ for ; n < 0; n++ {
+ aerc.PrevTab()
+ }
+ } else {
+ ok := aerc.SelectTabIndex(n)
+ if !ok {
+ return errors.New(
+ "No tab with that index")
+ }
+ }
+ } else {
+ ok := aerc.SelectTab(args[1])
+ if !ok {
+ return errors.New("No tab with that name")
+ }
}
}
return nil
M doc/aerc.1.scd => doc/aerc.1.scd +4 -2
@@ 36,8 36,10 @@ These commands work in any context.
*cd* <directory>
Changes aerc's current working directory.
-*change-tab* <tabname>
- Changes the focus to the tab with the name.
+*change-tab* [+|-]<tab name or index>
+ Changes the focus to the tab with the given name. If a number is given,
+ it's treated as an index. If + or - is specified, the number is interpreted
+ as a delta from the selected tab.
*exec* <command...>
Executes an arbitrary command in the background.
M widgets/aerc.go => widgets/aerc.go +10 -0
@@ 268,6 268,16 @@ func (aerc *Aerc) SelectTab(name string) bool {
return false
}
+func (aerc *Aerc) SelectTabIndex(index int) bool {
+ for i, _ := range aerc.tabs.Tabs {
+ if i == index {
+ aerc.tabs.Select(i)
+ return true
+ }
+ }
+ return false
+}
+
func (aerc *Aerc) TabNames() []string {
var names []string
for _, tab := range aerc.tabs.Tabs {