aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoritz Poldrack <git@moritz.sh>2023-05-09 17:19:44 +0200
committerRobin Jarry <robin@jarry.cc>2023-05-16 13:56:58 +0200
commitd22f2bf4d0a88b5a0e608e2cb2776e69eb1cd553 (patch)
tree7e5648c9ebb6dd599c7f1ad662058389f6d4fd7b
parentecfb22ad85bffb76b814b60ed82b48d0a245b32b (diff)
downloadaerc-d22f2bf4d0a88b5a0e608e2cb2776e69eb1cd553.tar.gz
aerc-d22f2bf4d0a88b5a0e608e2cb2776e69eb1cd553.zip
mkdir: add completion
In order to combat potential issues of not knowing ones servers delimiter when creating directories, the delimiter is automatically appended to all suggested matches. Signed-off-by: Moritz Poldrack <git@moritz.sh> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--CHANGELOG.md1
-rw-r--r--commands/account/mkdir.go20
2 files changed, 20 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a4b73809..435ddd62 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Warn before sending emails with an empty subject with `empty-subject-warning`
in `aerc.conf`.
- IMAP now uses the delimiter advertised by the server
+- Completions for `:mkdir`
### Fixed
diff --git a/commands/account/mkdir.go b/commands/account/mkdir.go
index 8a260c05..02d997e4 100644
--- a/commands/account/mkdir.go
+++ b/commands/account/mkdir.go
@@ -20,7 +20,25 @@ func (MakeDir) Aliases() []string {
}
func (MakeDir) Complete(aerc *widgets.Aerc, args []string) []string {
- return nil
+ if len(args) == 0 {
+ return nil
+ }
+ name := strings.Join(args, " ")
+
+ list := aerc.SelectedAccount().Directories().List()
+ inboxes := make([]string, len(list))
+ copy(inboxes, list)
+
+ // remove inboxes that don't match and append the path separator to all
+ // others
+ for i := len(inboxes) - 1; i >= 0; i-- {
+ if !strings.HasPrefix(inboxes[i], name) && name != "" {
+ inboxes = append(inboxes[:i], inboxes[i+1:]...)
+ continue
+ }
+ inboxes[i] += aerc.SelectedAccount().Worker().PathSeparator()
+ }
+ return inboxes
}
func (MakeDir) Execute(aerc *widgets.Aerc, args []string) error {