sendemail: teach git-send-email to list aliases
PATCH v2 1/2 sendemail: teach git-send-email to list aliases
From: Jacob Keller <[email protected]>
Add an option "list-aliases" which changes the default behavior of git-send-email. This mode will simply read the alias files configured by sendemail.aliasesfile and sendemail.aliasfiletype and print a list of all known aliases. The intended usecase for this option is the bash-completion script which will use it to autocomplete aliases on the options which take addresses.
--- Documentation/git-send-email.txt | 10 ++++++++++ git-send-email.perl | 11 +++++++++++ 2 files changed, 21 insertions(+)
Documentation/git-send-email.txt +10 -0
@@ -10,6 +10,7 @@ SYNOPSIS -------- [verse] 'git send-email' [options] <file|directory|rev-list options>... +'git send-email' --list-aliases DESCRIPTION
@@ -387,6 +388,15 @@ default to '--validate'. Send emails even if safety checks would prevent it. +Information +~~~~~~~~~~~ + +--list-aliases:: + Instead of the standard operation, list all aliases found in the + configured alias file(s), and then exit. See 'sendemail.aliasesfile' + for more information about aliases. + + CONFIGURATION -------------
git-send-email.perl +11 -0
@@ -46,6 +46,7 @@ package main; sub usage { print <<EOT; git send-email [options] <file | directory | rev-list options > +git send-email --list-aliases Composing: --from <str> * Email From:
@@ -101,6 +102,9 @@ git send-email [options] <file | directory | rev-list options > `git format-patch` ones. --force * Send even if safety checks would prevent it. + Information: + --list-aliases * read the aliases from configured alias files + EOT exit(1); }
@@ -180,6 +184,7 @@ my ($quiet, $dry_run) = (0, 0); my $format_patch; my $compose_filename; my $force = 0; +my $list_aliases = 0; # Handle interactive edition of files. my $multiedit;
@@ -344,6 +349,7 @@ my $rc = GetOptions("h" => \$help, "force" => \$force, "xmailer!" => \$use_xmailer, "no-xmailer" => sub {$use_xmailer = 0}, + "list-aliases" => \$list_aliases, ); usage() if $help;
@@ -551,6 +557,11 @@ if (@alias_files and $aliasfiletype and defined $parse_alias{$aliasfiletype}) { } } +if ($list_aliases) { + print $_,"\n" for (keys %aliases); + exit(0); +} + # is_format_patch_arg($f) returns 0 if $f names a patch, or 1 if # $f is a revision list specification to be passed to format-patch. sub is_format_patch_arg {
Signature · 1 line
2.6.3.491.g3e3f6ce
PATCH v2 2/2 completion: add support for completing email aliases
From: Jacob Keller <[email protected]>
Using the new --list-aliases option from git-send-email, add completion for --to, --cc, and --bcc with the available configured aliases.
---
Notes:
- v2
* reuse parsing from git-send-email via --list-aliases
contrib/completion/git-completion.bash | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
contrib/completion/git-completion.bash +16 -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
@@ -1711,6 +1712,15 @@ __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all" _git_send_email () { + case "$prev" in + --to|--cc|--bcc) + __gitcomp " + $(git --git-dir="$(__gitdir)" send-email --list-aliases 2>/dev/null) + " "" "" + return + ;; + esac + case "$cur" in --confirm=*) __gitcomp "
@@ -1735,6 +1745,12 @@ _git_send_email () " "" "${cur##--thread=}" return ;; + --to=*|--cc=*|--bcc=*) + __gitcomp " + $(git --git-dir="$(__gitdir)" send-email --list-aliases 2>/dev/null) + " "" "${cur#--*=}" + return + ;; --*) __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to --compose --confirm= --dry-run --envelope-sender
Signature · 1 line
2.6.3.491.g3e3f6ce
Re: [PATCH v2 2/2] completion: add support for completing email aliases
contrib/completion/git-completion.bash __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all" · line 1716
Quoted 12 lines · Jacob Keller
Using the new --list-aliases option from git-send-email, add completion for --to, --cc, and --bcc with the available configured aliases.
Signed-off-by Jacob Keller <[email protected]>---
contrib/completion/git-completion.bash +2
-0@@ -1711,6 +1712,15 @@ __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all" _git_send_email () { + case "$prev" in + --to|--cc|--bcc)
What about --from, which also undergoes alias expansion?
Quoted 25 lines
contrib/completion/git-completion.bash +13
-1+ __gitcomp " + $(git --git-dir="$(__gitdir)" send-email --list-aliases 2>/dev/null) + " "" "" + return + ;; + esac + case "$cur" in --confirm=*) __gitcomp "@@ -1735,6 +1745,12 @@ _git_send_email () " "" "${cur##--thread=}" return ;; + --to=*|--cc=*|--bcc=*) + __gitcomp " + $(git --git-dir="$(__gitdir)" send-email --list-aliases 2>/dev/null) + " "" "${cur#--*=}" + return + ;; --*) __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to --compose --confirm= --dry-run --envelope-sender --2.6.3.491.g3e3f6ce
Re: [PATCH v2 2/2] completion: add support for completing email aliases
Quoted 13 lines · Eric Sunshine
Quoted 11 lines · Jacob Keller
Using the new --list-aliases option from git-send-email, add completion
for --to, --cc, and --bcc with the available configured aliases.Signed-off-by Jacob Keller <[email protected]>---
contrib/completion/git-completion.bash +0
-0@@ -1711,6 +1712,15 @@ __git_send_email_suppresscc_options="authorself cc bodycc sob cccmd body all"
Quoted 7 lines
Quoted 4 lines
_git_send_email ()
{
+ case "$prev" in
+ --to|--cc|--bcc)What about --from, which also undergoes alias expansion?
Makes sense, yep.
Quoted 6 lines · Jacob Keller
Add an option "list-aliases" which changes the default behavior of git-send-email. This mode will simply read the alias files configured by sendemail.aliasesfile and sendemail.aliasfiletype and print a list of all known aliases. The intended usecase for this option is the bash-completion script which will use it to autocomplete aliases on the options which take addresses.
As this is primarily a plumbing option, I wonder if --dump-aliases might be a more suitable name.
Also, is it possible that some consumer down the road might want richer output which includes the expansion of each alias? For instance, it could emit the alias name as the first token on each line and the expansion as the remainder. Consumers interested in only the alias name would grab the first token on the line and ignore everything else.
git-send-email.perl git send-email [options] <file | directory | rev-list options > · line 106
Quoted 9 lines
Signed-off-by Jacob Keller <[email protected]>---
git-send-email.perl +2
-0@@ -101,6 +102,9 @@ git send-email [options] <file | directory | rev-list options > `git format-patch` ones. --force * Send even if safety checks would prevent it. + Information: + --list-aliases * read the aliases from configured alias files
This description is odd. It seems to imply that aliases will be loaded (and used) only if this option is given, and says nothing about its actual purpose of dumping the aliases.
Also, with one exception, all the other option descriptions are capitalized. This probably ought to follow suit.
git-send-email.perl if (@alias_files and $aliasfiletype and defined $parse_alias{$aliasfiletype}) { · line 563
Quoted 4 lines
git-send-email.perl +4
-0+if ($list_aliases) { + print $_,"\n" for (keys %aliases); + exit(0); +}
New test(s) seem to be missing.
Quoted 12 lines · Eric Sunshine
Quoted 9 lines · Jacob Keller
Add an option "list-aliases" which changes the default behavior of git-send-email. This mode will simply read the alias files configured by
sendemail.aliasesfile and sendemail.aliasfiletype and print a list of
all known aliases. The intended usecase for this option is the bash-completion script which will use it to autocomplete aliases on the
options which take addresses.
Quoted 3 lines
As this is primarily a plumbing option, I wonder if --dump-aliases might be a more suitable name.
Sure that would be reasonable.
Quoted 8 lines
Also, is it possible that some consumer down the road might want richer output which includes the expansion of each alias? For instance, it could emit the alias name as the first token on each line
and the expansion as the remainder. Consumers interested in only the alias name would grab the first token on the line and ignore everything else.
Maybe? The problem with printing the full address is that it may not be quoted or similar, and it makes the bash completion require an extra parameter.. I am not sure how valuable the alias expansion would be for use? The main concern I have is we'd need to use another process on top to extract only alias names.
Quoted 9 lines
Quoted 9 lines
Signed-off-by Jacob Keller <[email protected]>---
git-send-email.perl +0
-0@@ -101,6 +102,9 @@ git send-email [options] <file | directory |rev-list options >
git format-patchones. --force * Send even if safety checks would prevent it.
Quoted 9 lines
Quoted 3 lines
+ Information:
+ --list-aliases * read the aliases from configured alias filesThis description is odd. It seems to imply that aliases will be loaded
(and used) only if this option is given, and says nothing about its actual purpose of dumping the aliases.
I can re-word this.
Quoted 10 lines
Also, with one exception, all the other option descriptions are capitalized. This probably ought to follow suit.
git-send-email.perl if (@alias_files and $aliasfiletype and defined $parse_alias{$aliasfiletype}) { · line 563
Quoted 4 lines
git-send-email.perl +4
-0+if ($list_aliases) { + print $_,"\n" for (keys %aliases); + exit(0); +}New test(s) seem to be missing.
I had removed the tests from the old version because they weren't necessary anymore. New ones wouldn't hurt here either, though.. I'll work on that.
Regards,
Jake
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · Jacob E
Quoted 7 lines · Eric Sunshine
Also, is it possible that some consumer down the road might want richer output which includes the expansion of each alias? For instance, it could emit the alias name as the first token on each line
and the expansion as the remainder. Consumers interested in only the alias name would grab the first token on the line and ignore everything else.
Quoted 5 lines
Maybe? The problem with printing the full address is that it may not be quoted or similar, and it makes the bash completion require an extra parameter.. I am not sure how valuable the alias expansion would be for use? The main concern I have is we'd need to use another process on top to extract only alias names.
It should be possible to extract the alias within the shell itself without a separate process. For instance:
read alias rest
will leave the first token in $alias and the remainder of the line in $rest, and it's all done within the shell process.
Quoted 5 lines
Quoted 1 line
New test(s) seem to be missing.
I had removed the tests from the old version because they weren't necessary anymore. New ones wouldn't hurt here either, though.. I'll work on that.
I'm not sure which tests you mean, but I was referring to tests to make sure that git-send-email recognizes --list-aliases (or --dump-aliases if you switch to that) and that it produces the expected output in the expected format.
Also, shouldn't --list-aliases (or --dump-aliases) be mutually exclusive with many of the other options? New tests would check such exclusivity as well.
Quoted 8 lines · Eric Sunshine
It should be possible to extract the alias within the shell itself without a separate process. For instance:
read alias rest
will leave the first token in $alias and the remainder of the line in $rest, and it's all done within the shell process.
I'll look into this :)
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
New test(s) seem to be missing.
I had removed the tests from the old version because they weren't necessary anymore. New ones wouldn't hurt here either, though.. I'll
work on that.
Quoted 5 lines
I'm not sure which tests you mean, but I was referring to tests to make sure that git-send-email recognizes --list-aliases (or --dump-aliases if you switch to that) and that it produces the expected output in the expected format.
Yep, I added some in my respin.
Quoted 3 lines
Also, shouldn't --list-aliases (or --dump-aliases) be mutually exclusive with many of the other options? New tests would check such exclusivity as well.
I am at a loss for how to do that correctly in the perl. Help would be appreciated here.
Regards,
Jak
Quoted 10 lines · Jacob E
Quoted 7 lines · Eric Sunshine
It should be possible to extract the alias within the shell itself without a separate process. For instance:
read alias rest
will leave the first token in $alias and the remainder of the line in $rest, and it's all done within the shell process.
I'll look into this :)
My reason for asking is concern about scripts possibly breaking if someone comes along and wants to "fix" --dump-aliases to also dump the alias expansions. One possibility is just to punt today and say that when that feature is needed in the future, then that someone can add a --verbose option to complement --dump-aliases which would emit the alias expansions as well. One nice thing about punting at this point is that we don't (today) have to define a format for the output of the expansions. If we did want to think about it, one verbose, non-ambiguous format would be to show the alias name on a line by itself, and each expansion value on a line by itself indented by a tab. For instance:
managers
bob
fred
devs
jane
john
Quoted 6 lines
Quoted 3 lines
Also, shouldn't --list-aliases (or --dump-aliases) be mutually exclusive with many of the other options? New tests would check such exclusivity as well.
I am at a loss for how to do that correctly in the perl. Help would be appreciated here.
Since git-send-email.perl already configures GetOpt::Long with the 'pass_through' option, one possibility would be to invoke GetOptions() once for --list-aliases (or --dump-aliases), and then again for the normal options. Doing so may be a bit ugly; on the other hand, it does indicate pretty clearly that --list-aliases is a distinct "mode" of operation. On top of your patch, it might look something like this:
--- 8< ---
git-send-email.perl +6 -1
@@ -296,6 +296,12 @@ $SIG{INT} = \&signal_handler; my $help; my $rc = GetOptions("h" => \$help, + "list-aliases" => \$list_aliases); +usage() unless $rc; +die "--list-aliases incompatible with other options\n" + if !$help and $list_aliases and @ARGV; + +$rc = GetOptions( "sender|from=s" => \$sender, "in-reply-to=s" => \$initial_reply_to, "subject=s" => \$initial_subject,
@@ -349,7 +355,6 @@ my $rc = GetOptions("h" => \$help, "force" => \$force, "xmailer!" => \$use_xmailer, "no-xmailer" => sub {$use_xmailer = 0}, - "list-aliases" => \$list_aliases, ); usage() if $help;
--- 8< ---
Though, it may be overkill for this minor use-case.
Quoting Eric Sunshine <[email protected]>:
Quoted 9 lines · Jacob E
Quoted 8 lines · Eric Sunshine
Quoted 7 lines
It should be possible to extract the alias within the shell itself without a separate process. For instance:
read alias rest
will leave the first token in $alias and the remainder of the line in $rest, and it's all done within the shell process.
Actually, putting this read in a while loop and feeding 'git send-email's output into that does fork() a subshell:
$ echo "outside: $BASH_SUBSHELL" |while read line ; do echo "$line inside: $BASH_SUBSHELL" ; done outside: 0 inside: 1
Quoted 10 lines
Quoted 1 line
I'll look into this :)
My reason for asking is concern about scripts possibly breaking if someone comes along and wants to "fix" --dump-aliases to also dump the alias expansions. One possibility is just to punt today and say that when that feature is needed in the future, then that someone can add a --verbose option to complement --dump-aliases which would emit the alias expansions as well. One nice thing about punting at this point is that we don't (today) have to define a format for the output of the expansions.
I think we should cross the bridge when we get to it.
However, we could still be nice to that brave soul who might want to cross it in the future, and since at this point we are interested in listing only alias names, perhaps we should not appropriate the broader '--dump-alias' option, but go with the more specific '--dump-alias-names' instead.
Gábor
Quoted 9 lines · SZEDER Gábor
Quoting Eric Sunshine <[email protected]>:
Quoted 6 lines · Jacob E
Quoted 5 lines · Eric Sunshine
Quoted 3 lines
It should be possible to extract the alias within the shell itself without a separate process. For instance:
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
read alias rest
will leave the first token in $alias and the remainder of the line in $rest, and it's all done within the shell process.
Actually, putting this read in a while loop and feeding 'git send-email's output into that does
fork()a subshell:
Yea, I realized this. One extra subshell isn't a big deal but if we can eliminate that it is good.
Quoted 17 lines
$ echo "outside: $BASH_SUBSHELL" |while read line ; do echo "$line inside: $BASH_SUBSHELL" ; done outside: 0 inside: 1Quoted 11 lines
Quoted 1 line
I'll look into this :)
My reason for asking is concern about scripts possibly breaking if someone comes along and wants to "fix" --dump-aliases to also dump the alias expansions. One possibility is just to punt today and say that when that feature is needed in the future, then that someone can add a --verbose option to complement --dump-aliases which would emit the alias expansions as well. One nice thing about punting at this point is that we don't (today) have to define a format for the output of the expansions.
Quoted 1 line
I think we should cross the bridge when we get to it.
Agreed.
Quoted 6 lines
However, we could still be nice to that brave soul who might want to cross it in the future, and since at this point we are interested in listing only alias names, perhaps we should not appropriate the broader '--dump-alias' option, but go with the more specific '--dump-alias-names' instead.
Disagree. I think the best approach for expanding --dump-aliases output is turning it into a keyword-option argument such as:
--dump-aliases=format
and we can say "historic reasons the format is always names only", then we can extend the support that way. I don't really think that "--dump-alias-names" is nice since then we'd need separate option if this ever does change, and it's rather long if it never changes.
I suspect it won't be something people need either.
Regards,
Jake
Quoted 3 lines
Gábor
Quoted 36 lines · Eric Sunshine
Since git-send-email.perl already configures
GetOpt::Longwith the 'pass_through' option, one possibility would be to invokeGetOptions()once for --list-aliases (or --dump-aliases), and then again for the normal options. Doing so may be a bit ugly; on the other hand, it does indicate pretty clearly that --list-aliases is a distinct "mode" of operation. On top of your patch, it might look something like this:--- 8< ---
git-send-email.perl +6
-2@@ -296,6 +296,12 @@ $SIG{INT} = \&signal_handler; my $help; my $rc = GetOptions("h" => \$help, + "list-aliases" => \$list_aliases); +usage() unless $rc; +die "--list-aliases incompatible with other options\n" + if !$help and $list_aliases and @ARGV; + +$rc = GetOptions( "sender|from=s" => \$sender, "in-reply-to=s" => \$initial_reply_to, "subject=s" => \$initial_subject,@@ -349,7 +355,6 @@ my $rc = GetOptions("h" => \$help, "force" => \$force, "xmailer!" => \$use_xmailer, "no-xmailer" => sub {$use_xmailer = 0}, - "list-aliases" => \$list_aliases, ); usage() if $help; --- 8< ---
Quoted 1 line
Though, it may be overkill for this minor use-case.
I actually really like this approach. I will squash it in.
Regards,
Jake
Quoted 3 lines · Eric Sunshine
Also, shouldn't --list-aliases (or --dump-aliases) be mutually exclusive with many of the other options? New tests would check such exclusivity as well.
In fact, while I agree with Szeder that it makes sense to re-use send-email's aliases parsing functionality (and was going to suggest the same, but he beat me to it), this new option is awfully orthogonal to the overall purpose of send-email, thus, doesn't really fit in well and almost cries out for a command of its own which would be used by send-email and bash completion (though I'm not convinced that it's worth going that route for this one minor use-case).
Quoted 7 lines · Eric Sunshine
Quoted 4 lines · Eric Sunshine
Also, shouldn't --list-aliases (or --dump-aliases) be mutually exclusive with many of the other options? New tests would check such
exclusivity as well.
Quoted 9 lines
In fact, while I agree with Szeder that it makes sense to re-use send-email's aliases parsing functionality (and was going to suggest the same, but he beat me to it), this new option is awfully orthogonal
to the overall purpose of send-email, thus, doesn't really fit in well
and almost cries out for a command of its own which would be used by send-email and bash completion (though I'm not convinced that it's worth going that route for this one minor use-case).
I don't think it's worth it at this point, because we'd have to extract out the alias parsing logic from send-email, which is not easy.
The option is pretty orthogonal to git-send-email, but until/unless git-send-email is re-implemented in C, i don't really see value in trying to separate the logic out... That is a lot more effort for very little gain.
Regards,
Jake