git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 36/47] completion: zsh: add __gitcompadd helper

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Jan 1, 2021, 02:16 UTC
Message-ID
<20210101021622.798041-37-felipe.contreras@gmail.com>
In-Reply-To
<20210101021622.798041-1-felipe.contreras@gmail.com>
So we don't have to do the same over and over.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.zsh | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 82a4d6f470..4e9699f542 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -49,12 +49,16 @@ COMP_WORDBREAKS=':'
 GIT_SOURCING_ZSH_COMPLETION=y . "$script"
 functions[complete]="$old_complete"
 
+__gitcompadd ()
+{
+	compadd -p "${2-}" -S "${3- }" -- ${=1} && _ret=0
+}
+
 __gitcomp ()
 {
 	emulate -L zsh
 
-	local IFS=$' \t\n'
-	compadd -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
+	IFS=$' \t\n' __gitcompadd "$1" "${2-}" "${4- }"
 }
 
 __gitcomp_opts ()
@@ -69,7 +73,7 @@ __gitcomp_opts ()
 	for c in ${=1}; do
 		if [[ $c == "--" ]]; then
 			[[ "$cur_" == --no-* ]] && continue
-			compadd -S " " -- "--no-..." && _ret=0
+			__gitcompadd "--no-..."
 			break
 		fi
 
@@ -81,7 +85,7 @@ __gitcomp_opts ()
 		else
 			sfx="$4"
 		fi
-		compadd -S "$sfx" -p "${2-}" -- "$c" && _ret=0
+		__gitcompadd "$c" "${2-}" "$sfx"
 	done
 }
 
-- 
2.30.0
Previous: Felipe ContrerasNext: Felipe Contreras
Message 29 of 48 in “completion: git-completion 1.3 patches”
  1. 00/47 completion: git-completion 1.3 patchesFelipe Contreras, Jan 1, 2021
  2. 06/47 test: completion: fix currently typed wordsFelipe Contreras, Jan 1, 2021
  3. 05/47 completion: bash: do not modify COMP_WORDBREAKSFelipe Contreras, Jan 1, 2021
  4. 15/47 completion: zsh: fix for undefined completionsFelipe Contreras, Jan 1, 2021
  5. 02/47 completion: fix for suboptions with valueFelipe Contreras, Jan 1, 2021
  6. 13/47 completion: zsh: expand --git-dir file argumentFelipe Contreras, Jan 1, 2021
  7. 01/47 completion: bash: fix prefix detection in branch.*Felipe Contreras, Jan 1, 2021
  8. 04/47 completion: bash: add correct suffix in variablesFelipe Contreras, Jan 1, 2021
  9. 03/47 completion: bash: fix for multiple dash commandsFelipe Contreras, Jan 1, 2021
  10. 07/47 test: completion: switch __gitcomp_nl prefix testFelipe Contreras, Jan 1, 2021
  11. 10/47 completion: bash: get rid of _append() functionsFelipe Contreras, Jan 1, 2021
  12. 08/47 test: completion: add run_func() helperFelipe Contreras, Jan 1, 2021
  13. 17/47 completion: zsh: fix extra space on foo=Felipe Contreras, Jan 1, 2021
  14. 23/47 completion: simplify __gitcompFelipe Contreras, Jan 1, 2021
  15. 21/47 completion: simplify equal suffix checkFelipe Contreras, Jan 1, 2021
  16. 19/47 completion: zsh: always set compsetFelipe Contreras, Jan 1, 2021
  17. 27/47 test: completion: add missing testFelipe Contreras, Jan 1, 2021
  18. 11/47 completion: bash: get rid of any non-append codeFelipe Contreras, Jan 1, 2021
  19. 25/47 completion: improve __gitcomp suffix codeFelipe Contreras, Jan 1, 2021
  20. 28/47 completion: bash: improve __gitcomp descriptionFelipe Contreras, Jan 1, 2021
  21. 12/47 completion: zsh: fix options with argumentsFelipe Contreras, Jan 1, 2021
  22. 14/47 completion: zsh: add support for general -C optsFelipe Contreras, Jan 1, 2021
  23. 16/47 completion: zsh: add support for general -c optsFelipe Contreras, Jan 1, 2021
  24. 29/47 completion: add __gitcomp_optsFelipe Contreras, Jan 1, 2021
  25. 30/47 completion: bash: cleanup __gitcomp* invocationsFelipe Contreras, Jan 1, 2021
  26. 09/47 completion: bash: remove non-append functionalityFelipe Contreras, Jan 1, 2021
  27. 33/47 completion: zsh: shuffle __gitcomp* functionsFelipe Contreras, Jan 1, 2021
  28. 35/47 completion: zsh: add elements individually in __gitcomp_optsFelipe Contreras, Jan 1, 2021
  29. 36/47 completion: zsh: add __gitcompadd helperFelipe Contreras, Jan 1, 2021
  30. 31/47 completion: bash: shuffle __gitcomp functionsFelipe Contreras, Jan 1, 2021
  31. 38/47 completion: bash: simplify _get_comp_words_by_ref()Felipe Contreras, Jan 1, 2021
  32. 37/47 completion: zsh: add correct removable suffixFelipe Contreras, Jan 1, 2021
  33. 39/47 completion: bash: refactor _get_comp_words_by_ref()Felipe Contreras, Jan 1, 2021
  34. 32/47 completion: zsh: simplify __gitcomp_directFelipe Contreras, Jan 1, 2021
  35. 40/47 completion: bash: cleanup _get_comp_words_by_ref()Felipe Contreras, Jan 1, 2021
  36. 18/47 completion: zsh: add excluded optionsFelipe Contreras, Jan 1, 2021
  37. 20/47 completion: factor out check in __gitcompFelipe Contreras, Jan 1, 2021
  38. 22/47 completion: refactor __gitcompFelipe Contreras, Jan 1, 2021
  39. 24/47 completion: bash: change suffix check in __gitcompFelipe Contreras, Jan 1, 2021
  40. 44/47 completion: bash: improve function detectionFelipe Contreras, Jan 1, 2021
  41. 26/47 completion: bash: simplify config_variable_nameFelipe Contreras, Jan 1, 2021
  42. 45/47 test: completion: add tests for __git_completeFelipe Contreras, Jan 1, 2021
  43. 47/47 completion: zsh: add higher-priority locationFelipe Contreras, Jan 1, 2021
  44. 42/47 completion: bash: rename _get_comp_words_by_ref()Felipe Contreras, Jan 1, 2021
  45. 34/47 completion: zsh: fix direct quotingFelipe Contreras, Jan 1, 2021
  46. 41/47 completion: bash: trivial cleanupFelipe Contreras, Jan 1, 2021
  47. 43/47 completion: bash: add __git_have_func helperFelipe Contreras, Jan 1, 2021
  48. 46/47 completion: add proper public __git_completeFelipe Contreras, Jan 1, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.