summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffas <dev@jeffas.io>2019-07-26 22:41:13 +0100
committerDrew DeVault <sir@cmpwn.com>2019-07-27 12:40:28 -0400
commit989730d47000feb297b5fab4e273a9d9b13c5741 (patch)
tree061b5ef3a8d8d6521f4806fbb11e9d0f5ea4dc0c
parent0ee7d30187920751c6e79facbd87ebce86d62ec9 (diff)
downloadaerc-989730d47000feb297b5fab4e273a9d9b13c5741.zip
Add index option to change-tab
This allows selection of a tab using its index. It attempts to parse the given argument as a number, if it fails then it uses it as a name. Also supports relative indexes using prefixed + or -.
-rw-r--r--commands/ct.go27
-rw-r--r--doc/aerc.1.scd6
-rw-r--r--widgets/aerc.go10
3 files changed, 37 insertions, 6 deletions
diff --git a/commands/ct.go b/commands/ct.go
index 19fb63a..4e66331 100644
--- a/commands/ct.go
+++ b/commands/ct.go
@@ -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
diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd
index 206e9b1..c158422 100644
--- a/doc/aerc.1.scd
+++ b/doc/aerc.1.scd
@@ -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.
diff --git a/widgets/aerc.go b/widgets/aerc.go
index 458c2f9..90b56c8 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -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 {