completion: add support for completing email aliases
RFC PATCH 1/1 completion: add support for completing email aliases
From: Jacob Keller <[email protected]>
Extract email aliases from the sendemail.aliasesfile according to the known types. Implementation only extracts the alias name and does not attempt to complete email addresses.
Add a few tests for simple layouts of the currently supported alias filetypes.
---
Labeled this RFC because I have only been able to test the mutt format as this is what I use locally. I have a few (probably brittle) test cases for the files, but they are not "real" configuration files as per the upstream tools, so they are essentially made to work with the simple extractors that I have now. I'd like some review on this to see if it's valuable, but it definitely helps me type out aliases and see what is available by just using TAB.
contrib/completion/git-completion.bash | 69 ++++++++++++++++++++++++++ t/t9902-completion.sh | 90 ++++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+)
contrib/completion/git-completion.bash +69 -0
@@ -10,6 +10,7 @@ # *) local and remote tag names # *) .git/remotes file names # *) git 'subcommands' +# *) git email aliases for git-send-email # *) tree paths within 'ref:path/to/file' expressions # *) file paths within current working directory and index # *) common --long-options
@@ -785,6 +786,56 @@ __git_aliased_command () done } +# Print aliases for email addresses from sendemail.aliasesfile +__git_email_aliases () +{ + local file="$(git --git-dir="$(__gitdir)" config --path sendemail.aliasesfile)" + local filetype="$(git --git-dir="$(__gitdir)" config sendemail.aliasfiletype)" + + # Only run awk if we find an actual file + if ! [ -f $file ]; then + return + fi + + case "$filetype" in + # Each file type needs to be parsed differently. + mutt|mailrc) + # Mutt and mailrc are simple and just put the alias in + # the 2nd field of the file. + awk '{print $2}' $file + return + ;; + sendmail) + # Skip new lines, lines without fields, and lines + # ending in '\' then print the name minus the final : + awk 'NF && $1!~/^#/ && !/\\$/ {sub(/:$/, "", $1); print $1 }' $file + return + ;; + pine) + # According to spec, line continuations are any line + # which starts with whitespace, otherwise we can just + # use the normal separator and print the first field. + awk '/^\S/ {print $1}' "$file" + return + ;; + elm) + # Elm doesn't appear to allow newlines, and + # git-send-email only accepts one alias per line, so + # just print the first field. + awk '{print $1}' "$file" + return + ;; + gnus) + # The gnus format has the alias quoted, so we just use + # gsub to extract the alias from the quotes + awk '/define-mail-alias/ {gsub(/"/, "", $2); print $2}' $file + return + ;; + *) + return;; + esac +} + # __git_find_on_cmdline requires 1 argument __git_find_on_cmdline () {
@@ -1735,6 +1786,24 @@ _git_send_email () " "" "${cur##--thread=}" return ;; + --to=*) + __gitcomp " + $(__git_email_aliases) + " "" "${cur##--to=}" + return + ;; + --cc=*) + __gitcomp " + $(__git_email_aliases) + " "" "${cur##--cc=}" + return + ;; + --bcc=*) + __gitcomp " + $(__git_email_aliases) + " "" "${cur##--bcc=}" + return + ;; --*) __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to --compose --confirm= --dry-run --envelope-sender
t/t9902-completion.sh +90 -0
96 lines not on this page · raw message
Signature · 1 line
2.6.1.264.gbab76a9