aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/account/cf.go44
-rw-r--r--commands/account/mkdir.go2
-rw-r--r--commands/account/query.go67
-rw-r--r--commands/account/rmdir.go4
4 files changed, 94 insertions, 23 deletions
diff --git a/commands/account/cf.go b/commands/account/cf.go
index 2f32e8bc..0f818006 100644
--- a/commands/account/cf.go
+++ b/commands/account/cf.go
@@ -103,35 +103,39 @@ func (c ChangeFolder) Execute([]string) error {
}
finalize := func(msg types.WorkerMessage) {
- // As we're waiting for the worker to report status we must run
- // the rest of the actions in this callback.
- switch msg := msg.(type) {
- case *types.Error:
- app.PushError(msg.Error.Error())
- case *types.Done:
- curAccount := app.SelectedAccount()
- previous := curAccount.Directories().Selected()
- history[curAccount.Name()] = previous
- // reset store filtering if we switched folders
- store := acct.Store()
- if store != nil {
- store.ApplyClear()
- acct.SetStatus(state.SearchFilterClear())
- }
- // focus account tab
- acct.Select()
- }
+ handleDirOpenResponse(acct, msg)
}
if target == "-" {
if dir, ok := history[acct.Name()]; ok {
- acct.Directories().Open(dir, 0*time.Second, finalize)
+ acct.Directories().Open(dir, "", 0*time.Second, finalize)
} else {
return errors.New("No previous folder to return to")
}
} else {
- acct.Directories().Open(target, 0*time.Second, finalize)
+ acct.Directories().Open(target, "", 0*time.Second, finalize)
}
return nil
}
+
+func handleDirOpenResponse(acct *app.AccountView, msg types.WorkerMessage) {
+ // As we're waiting for the worker to report status we must run
+ // the rest of the actions in this callback.
+ switch msg := msg.(type) {
+ case *types.Error:
+ app.PushError(msg.Error.Error())
+ case *types.Done:
+ curAccount := app.SelectedAccount()
+ previous := curAccount.Directories().Selected()
+ history[curAccount.Name()] = previous
+ // reset store filtering if we switched folders
+ store := acct.Store()
+ if store != nil {
+ store.ApplyClear()
+ acct.SetStatus(state.SearchFilterClear())
+ }
+ // focus account tab
+ acct.Select()
+ }
+}
diff --git a/commands/account/mkdir.go b/commands/account/mkdir.go
index c08c6d4b..9776e8f7 100644
--- a/commands/account/mkdir.go
+++ b/commands/account/mkdir.go
@@ -53,7 +53,7 @@ func (m MakeDir) Execute(args []string) error {
case *types.Done:
app.PushStatus("Directory created.", 10*time.Second)
history[acct.Name()] = previous
- acct.Directories().Open(m.Folder, 0, nil)
+ acct.Directories().Open(m.Folder, "", 0, nil)
case *types.Error:
app.PushError(msg.Error.Error())
}
diff --git a/commands/account/query.go b/commands/account/query.go
new file mode 100644
index 00000000..f116d405
--- /dev/null
+++ b/commands/account/query.go
@@ -0,0 +1,67 @@
+package account
+
+import (
+ "errors"
+ "reflect"
+ "time"
+
+ "git.sr.ht/~rjarry/aerc/app"
+ "git.sr.ht/~rjarry/aerc/commands"
+ "git.sr.ht/~rjarry/aerc/worker/handlers"
+ "git.sr.ht/~rjarry/aerc/worker/types"
+)
+
+type Query struct {
+ Account string `opt:"-a" complete:"CompleteAccount"`
+ Name string `opt:"-n"`
+ Query string `opt:"..."`
+}
+
+func init() {
+ commands.Register(Query{})
+}
+
+func (Query) Context() commands.CommandContext {
+ return commands.ACCOUNT
+}
+
+func (Query) Aliases() []string {
+ return []string{"query"}
+}
+
+func (Query) CompleteAccount(arg string) []string {
+ return commands.FilterList(app.AccountNames(), arg, commands.QuoteSpace)
+}
+
+func (q Query) Execute([]string) error {
+ var acct *app.AccountView
+
+ if q.Account == "" {
+ acct = app.SelectedAccount()
+ if acct == nil {
+ return errors.New("No account selected")
+ }
+ } else {
+ var err error
+ acct, err = app.Account(q.Account)
+ if err != nil {
+ return err
+ }
+ }
+
+ notmuch, _ := handlers.GetHandlerForScheme("notmuch", new(types.Worker))
+ if reflect.TypeOf(notmuch) != reflect.TypeOf(acct.Worker().Backend) {
+ return errors.New(":query is only available for notmuch accounts")
+ }
+
+ finalize := func(msg types.WorkerMessage) {
+ handleDirOpenResponse(acct, msg)
+ }
+
+ name := q.Name
+ if name == "" {
+ name = q.Query
+ }
+ acct.Directories().Open(name, q.Query, 0*time.Second, finalize)
+ return nil
+}
diff --git a/commands/account/rmdir.go b/commands/account/rmdir.go
index 00366bd0..48ea3581 100644
--- a/commands/account/rmdir.go
+++ b/commands/account/rmdir.go
@@ -89,9 +89,9 @@ func (r RemoveDir) Execute(args []string) error {
return errors.New("No directory to move to afterwards!")
}
- reopenCurrentDir := func() { acct.Directories().Open(curDir, 0, nil) }
+ reopenCurrentDir := func() { acct.Directories().Open(curDir, "", 0, nil) }
- acct.Directories().Open(newDir, 0, func(msg types.WorkerMessage) {
+ acct.Directories().Open(newDir, "", 0, func(msg types.WorkerMessage) {
switch msg.(type) {
case *types.Done:
break