From 41197b766f5223c1d3f02594c9324b67c14c56ae Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Mon, 1 Oct 2018 10:39:21 +0200 Subject: Enable zsh completion of sender addresses This parses the config file to find the email addresses. Because the string interpolation happens at run time and not at load time of the completion script the python snippet is run on each completion attempt. This has the advantage that changes to the config file are picked up without restarting the shell and the snippet is simple enough to not impose a real delay in completion. --- extra/completion/alot-completion.zsh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'extra') diff --git a/extra/completion/alot-completion.zsh b/extra/completion/alot-completion.zsh index bbd3c54d..34d48a61 100644 --- a/extra/completion/alot-completion.zsh +++ b/extra/completion/alot-completion.zsh @@ -24,6 +24,18 @@ _alot_search() '--sort=[sort results]:sorting:((newest_first\:"reverse chronological order" oldest_first\:"chronological order" message_id\:"lexicographically by Message Id"))' } +_alot_account_emails() +{ + python3 - ${XDG_CONFIG_HOME:-~/.config}/alot/config <<-'EOF' + import configobj, sys + config = configobj.ConfigObj(infile=sys.argv[1], encoding="UTF8") + accounts = config.get("accounts", {}) + addresses = [accounts[k].get('address') for k in accounts + if type(accounts[k]) is configobj.Section] + print(" ".join(addresses), end="") + EOF +} + _alot_compose() { _arguments -s : \ @@ -31,7 +43,7 @@ _alot_compose() '--bcc=[Blind Carbon Copy header]:Recipient (Bcc header):_email_addresses' \ '--cc=[Carbon Copy header]:Recipient (Cc header):_email_addresses' \ '--omit_signature[do not add signature]' \ - '--sender=[From header]' \ + "--sender=[From header]:Sender account:($(_alot_account_emails))" \ '--subject=[Subject header]' \ '--template=[template file to use]' \ '--to=[To header]:Recipient (To header):_email_addresses' \ -- cgit v1.2.3