zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] completion: _git: Add trailer support for git commit --trailer
@ 2023-09-12 18:16 Wesley Schwengle
  2023-09-14  2:53 ` [PATCH v2]] completion: _git: Add trailer token completion " Wesley Schwengle
  0 siblings, 1 reply; 2+ messages in thread
From: Wesley Schwengle @ 2023-09-12 18:16 UTC (permalink / raw)
  To: zsh-workers

Via 842587016d717394a001a6f8959475bf8df56124 in the git project there has
been support for git commit trailer tokens for the bash completion
system. This commit adds similar support to zsh.

Signed-off-by: Wesley Schwengle <wesleys@opperschaap.net>
---
 Completion/Unix/Command/_git | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 1d4fe20c9..dd2c1ec74 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -717,7 +717,7 @@ _git-commit () {
     {-p,--patch}'[use the interactive patch selection interface to chose which changes to commit]' \
     '(--reset-author)--author[override the author name used in the commit]:author name' \
     '--date=[override the author date used in the commit]:date' \
-    '*--trailer=[add custom trailer(s)]:trailer' \
+    '*--trailer=[add custom trailer(s)]:trailer :__git_trailers_tokens' \
     '(-s --signoff)'{-s,--signoff}'[add Signed-off-by trailer at the end of the commit message]' \
     '(-n --no-verify)'{-n,--no-verify}'[bypass pre-commit and commit-msg hooks]' \
     '--allow-empty[allow recording an empty commit]' \
@@ -7413,6 +7413,19 @@ __git_deleted_files () {
   __git_files --deleted deleted-files 'deleted file' $*
 }
 
+
+(( $+functions[__git_trailers_tokens] )) ||
+__git_trailers_tokens () {
+  declare -a trailers
+
+  local -a gtrailers=($(git config --name-only --get-regexp trailer.\*.key))
+  for i ("$gtrailers[@]")
+  do
+    trailers+=(${${(@s:.:)i}[2]})
+  done
+  _wanted trailer expl "trailer" compadd -a trailers
+}
+
 (( $+functions[__git_modified_files] )) ||
 __git_modified_files () {
   __git_files --modified modified-files 'modified file' $*
-- 
2.42.0.465.g461bb28fbd



^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH v2]] completion: _git: Add trailer token completion for git commit --trailer
  2023-09-12 18:16 [PATCH] completion: _git: Add trailer support for git commit --trailer Wesley Schwengle
@ 2023-09-14  2:53 ` Wesley Schwengle
  0 siblings, 0 replies; 2+ messages in thread
From: Wesley Schwengle @ 2023-09-14  2:53 UTC (permalink / raw)
  To: zsh-workers

Via 842587016d in the git project there has been support for git commit
trailer tokens for the bash completion system. This commit adds similar
support to zsh. It includes additional hardening of the regexp and
allows for tokens which include a '.'. This can be found in git via
9a0ec17606.

Signed-off-by: Wesley Schwengle <wesleys@opperschaap.net>
---
 Completion/Unix/Command/_git | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 1d4fe20c9..3b9041303 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -717,7 +717,7 @@ _git-commit () {
     {-p,--patch}'[use the interactive patch selection interface to chose which changes to commit]' \
     '(--reset-author)--author[override the author name used in the commit]:author name' \
     '--date=[override the author date used in the commit]:date' \
-    '*--trailer=[add custom trailer(s)]:trailer' \
+    '*--trailer=[add custom trailer(s)]:trailer :__git_trailers_tokens' \
     '(-s --signoff)'{-s,--signoff}'[add Signed-off-by trailer at the end of the commit message]' \
     '(-n --no-verify)'{-n,--no-verify}'[bypass pre-commit and commit-msg hooks]' \
     '--allow-empty[allow recording an empty commit]' \
@@ -7413,6 +7413,20 @@ __git_deleted_files () {
   __git_files --deleted deleted-files 'deleted file' $*
 }
 
+
+(( $+functions[__git_trailers_tokens] )) ||
+__git_trailers_tokens () {
+  declare -a trailers
+
+  local -a gtrailers=($(git config --name-only --get-regexp '^trailer\..*\.key$'))
+  for i ("$gtrailers[@]")
+  do
+    i=(${${(@s:.:)i}[2,-2]});
+    trailers+=(${(j|.|)i})
+  done
+  _wanted trailer expl "trailer" compadd -a trailers
+}
+
 (( $+functions[__git_modified_files] )) ||
 __git_modified_files () {
   __git_files --modified modified-files 'modified file' $*
-- 
2.42.0.465.g461bb28fbd



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-09-14  2:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-12 18:16 [PATCH] completion: _git: Add trailer support for git commit --trailer Wesley Schwengle
2023-09-14  2:53 ` [PATCH v2]] completion: _git: Add trailer token completion " Wesley Schwengle

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).