[PATCH] mail: improve bash completion

Greg Kurz groug at kaod.org
Tue Nov 29 05:14:15 AEDT 2016


This adds completion of the --to, --cc and --bcc options based on the
content of the [mail "alias"] section of GIT configuration files.

Signed-off-by: Greg Kurz <groug at kaod.org>
---
 stgit/argparse.py      |    1 +
 stgit/commands/mail.py |    6 +++---
 stgit/completion.py    |    2 ++
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/stgit/argparse.py b/stgit/argparse.py
index 43c6cf9bbbb3..86f4a1095d10 100644
--- a/stgit/argparse.py
+++ b/stgit/argparse.py
@@ -286,6 +286,7 @@ known_files = Compgen(['$(_known_files)'])
 repo = Compgen(actions = ['directory'])
 dir = Compgen(actions = ['directory'])
 files = Compgen(actions = ['file'])
+mail_aliases = Compgen(['$(_mail_aliases)'])
 def strings(*ss): return Compgen(ss)
 class patch_range(CompgenBase):
     def __init__(self, *endpoints):
diff --git a/stgit/commands/mail.py b/stgit/commands/mail.py
index ff9f2e11ca36..2dc3dba6680d 100644
--- a/stgit/commands/mail.py
+++ b/stgit/commands/mail.py
@@ -102,11 +102,11 @@ args = [argparse.patch_range(argparse.applied_patches,
 options = [
     opt('-a', '--all', action = 'store_true',
         short = 'E-mail all the applied patches'),
-    opt('--to', action = 'append',
+    opt('--to', action = 'append', args = [argparse.mail_aliases],
         short = 'Add TO to the To: list'),
-    opt('--cc', action = 'append',
+    opt('--cc', action = 'append', args = [argparse.mail_aliases],
         short = 'Add CC to the Cc: list'),
-    opt('--bcc', action = 'append',
+    opt('--bcc', action = 'append', args = [argparse.mail_aliases],
         short = 'Add BCC to the Bcc: list'),
     opt('--auto', action = 'store_true',
         short = 'Automatically cc the patch signers'),
diff --git a/stgit/completion.py b/stgit/completion.py
index 38f06705b76a..010fc4fbee0c 100644
--- a/stgit/completion.py
+++ b/stgit/completion.py
@@ -58,6 +58,8 @@ def util():
              'esac'),
          fun('_stg_branches',
              'local g=$(_gitdir)', 'test "$g" && (cd $g/patches/ && echo *)'),
+         fun('_mail_aliases',
+             'git config --name-only --get-regexp "^mail\.alias\." | cut -d. -f 3'),
          ref_list_fun('_all_branches', 'refs/heads'),
          ref_list_fun('_tags', 'refs/tags'),
          ref_list_fun('_remotes', 'refs/remotes')]



More information about the Linuxppc-dev mailing list