diff options
author | Koni Marti <koni.marti@gmail.com> | 2023-11-24 16:03:09 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-12-30 15:42:09 +0100 |
commit | cfcab6c5c883a08afa3a56c11e4f48d9725be2a0 (patch) | |
tree | ed774c1acbbfb481ebd1b2a30b69169d9f9804a6 /commands/patch | |
parent | 8671d9dc483acf3c69022a8f2915166b83186559 (diff) | |
download | aerc-cfcab6c5c883a08afa3a56c11e4f48d9725be2a0.tar.gz |
patch/switch: add switch sub-cmd
Implement the :project switch command. Switch between different
projects.
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands/patch')
-rw-r--r-- | commands/patch/switch.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/commands/patch/switch.go b/commands/patch/switch.go new file mode 100644 index 00000000..b1193be7 --- /dev/null +++ b/commands/patch/switch.go @@ -0,0 +1,54 @@ +package patch + +import ( + "fmt" + "time" + + "git.sr.ht/~rjarry/aerc/app" + "git.sr.ht/~rjarry/aerc/commands" + "git.sr.ht/~rjarry/aerc/lib/pama" + "git.sr.ht/~rjarry/aerc/log" +) + +type Switch struct { + Project string `opt:"project" complete:"Complete"` +} + +func init() { + register(Switch{}) +} + +func (Switch) Aliases() []string { + return []string{"switch"} +} + +func (s Switch) Complete(arg string) []string { + m := pama.New() + names, err := m.Names() + if err != nil { + log.Errorf("failed to get completion: %v", err) + return nil + } + cur, err := m.CurrentProject() + if err == nil { + i := 0 + for ; i < len(names); i++ { + if cur.Name == names[i] { + names = append(names[:i], names[i+1:]...) + break + } + } + } + return commands.FilterList(names, arg, nil) +} + +func (s Switch) Execute(_ []string) error { + name := s.Project + err := pama.New().SwitchProject(name) + if err != nil { + return err + } + app.PushStatus(fmt.Sprintf("Project switched to '%s'", name), + 10*time.Second) + return nil +} |