diff options
author | Moritz Poldrack <git@moritz.sh> | 2023-05-09 17:19:44 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-05-16 13:56:58 +0200 |
commit | d22f2bf4d0a88b5a0e608e2cb2776e69eb1cd553 (patch) | |
tree | 7e5648c9ebb6dd599c7f1ad662058389f6d4fd7b /commands | |
parent | ecfb22ad85bffb76b814b60ed82b48d0a245b32b (diff) | |
download | aerc-d22f2bf4d0a88b5a0e608e2cb2776e69eb1cd553.tar.gz |
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>
Diffstat (limited to 'commands')
-rw-r--r-- | commands/account/mkdir.go | 20 |
1 files changed, 19 insertions, 1 deletions
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 { |