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 -
This commit is contained in:
parent
d526786c93
commit
e42b95a617
3 changed files with 90 additions and 5 deletions
commands
48
commands/ct.go
Normal file
48
commands/ct.go
Normal file
|
@ -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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue