From d22f2bf4d0a88b5a0e608e2cb2776e69eb1cd553 Mon Sep 17 00:00:00 2001 From: Moritz Poldrack Date: Tue, 9 May 2023 17:19:44 +0200 Subject: 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 Acked-by: Robin Jarry --- CHANGELOG.md | 1 + commands/account/mkdir.go | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) 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 { -- cgit v1.2.3-54-g00ecf