diff options
author | Jeffas <dev@jeffas.io> | 2020-03-02 19:54:42 +0000 |
---|---|---|
committer | Reto Brunner <reto@labrat.space> | 2020-03-03 20:08:29 +0100 |
commit | 68f179021d304d6edf939ecf5fc7d0d073b16152 (patch) | |
tree | 0ba86642579bfc7fa87ce38473ce234208277336 /commands | |
parent | 2e381fa42d64442262335101fe3b7bf76ab50b92 (diff) | |
download | aerc-68f179021d304d6edf939ecf5fc7d0d073b16152.tar.gz |
Add move-tab command
Diffstat (limited to 'commands')
-rw-r--r-- | commands/move-tab.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/commands/move-tab.go b/commands/move-tab.go new file mode 100644 index 00000000..9f0293c7 --- /dev/null +++ b/commands/move-tab.go @@ -0,0 +1,51 @@ +package commands + +import ( + "fmt" + "strconv" + "strings" + + "git.sr.ht/~sircmpwn/aerc/widgets" +) + +type MoveTab struct{} + +func init() { + register(MoveTab{}) +} + +func (MoveTab) Aliases() []string { + return []string{"move-tab"} +} + +func (MoveTab) Complete(aerc *widgets.Aerc, args []string) []string { + return nil +} + +func (MoveTab) Execute(aerc *widgets.Aerc, args []string) error { + if len(args) == 1 { + return fmt.Errorf("Usage: %s [+|-]<index>", args[0]) + } + + joinedArgs := strings.Join(args[1:], "") + + n, err := strconv.Atoi(joinedArgs) + if err != nil { + return fmt.Errorf("failed to parse index argument: %v", err) + } + + i := aerc.SelectedTabIndex() + l := aerc.NumTabs() + + if strings.HasPrefix(joinedArgs, "+") { + i = (i + n) % l + } else if strings.HasPrefix(joinedArgs, "-") { + i = (((i + n) % l) + l) % l + } else { + i = n + } + + aerc.MoveTab(i) + + return nil +} |