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

[PATCH 17/51] completion: bash: get rid of _append() functions

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Aug 30, 2022, 09:31 UTC
Message-ID
<20220830093138.1581538-18-felipe.contreras@gmail.com>
In-Reply-To
<20220830093138.1581538-1-felipe.contreras@gmail.com>
There's no need to have duplicated functionality.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash | 35 ++++++--------------------
 contrib/completion/git-completion.zsh  | 10 --------
 2 files changed, 7 insertions(+), 38 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 6571dc1b2d..4a7e75b48d 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -301,8 +301,7 @@ _get_comp_words_by_ref ()
 }
 fi
 
-# Fills the COMPREPLY array with prefiltered words without any additional
-# processing.
+# Appends prefiltered words to COMPREPLY without any additional processing.
 # Callers must take care of providing only words that match the current word
 # to be completed and adding any prefix and/or suffix (trailing space!), if
 # necessary.
@@ -315,19 +314,6 @@ __gitcomp_direct ()
 	COMPREPLY+=($1)
 }
 
-# Similar to __gitcomp_direct, but appends to COMPREPLY instead.
-# Callers must take care of providing only words that match the current word
-# to be completed and adding any prefix and/or suffix (trailing space!), if
-# necessary.
-# 1: List of newline-separated matching completion words, complete with
-#    prefix and suffix.
-__gitcomp_direct_append ()
-{
-	local IFS=$'\n'
-
-	COMPREPLY+=($1)
-}
-
 __gitcompappend ()
 {
 	local x i=${#COMPREPLY[@]}
@@ -445,16 +431,8 @@ __gitcomp_builtin ()
 	__gitcomp "$options"
 }
 
-# Variation of __gitcomp_nl () that appends to the existing list of
-# completion candidates, COMPREPLY.
-__gitcomp_nl_append ()
-{
-	local IFS=$'\n'
-	__gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
-}
-
 # Generates completion reply from newline-separated possible completion words
-# by appending a space to all of them.
+# by appending a space to all of them. The result is appended to COMPREPLY.
 # It accepts 1 to 4 arguments:
 # 1: List of possible completion words, separated by a single newline.
 # 2: A prefix to be added to each possible completion word (optional).
@@ -464,7 +442,8 @@ __gitcomp_nl_append ()
 #    appended.
 __gitcomp_nl ()
 {
-	__gitcomp_nl_append "$@"
+	local IFS=$'\n'
+	__gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }"
 }
 
 # Fills the COMPREPLY array with prefiltered paths without any additional
@@ -851,7 +830,7 @@ __git_complete_refs ()
 
 	# Append DWIM remote branch names if requested
 	if [ "$dwim" = "yes" ]; then
-		__gitcomp_direct_append "$(__git_dwim_remote_heads "$pfx" "$cur_" "$sfx")"
+		__gitcomp_direct "$(__git_dwim_remote_heads "$pfx" "$cur_" "$sfx")"
 	fi
 }
 
@@ -2650,7 +2629,7 @@ __git_complete_config_variable_name ()
 		local pfx="${cur_%.*}."
 		cur_="${cur_#*.}"
 		__gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
-		__gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "${sfx- }"
+		__gitcomp_nl $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "${sfx- }"
 		return
 		;;
 	guitool.*.*)
@@ -2700,7 +2679,7 @@ __git_complete_config_variable_name ()
 		local pfx="${cur_%.*}."
 		cur_="${cur_#*.}"
 		__gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
-		__gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "${sfx- }"
+		__gitcomp_nl "pushDefault" "$pfx" "$cur_" "${sfx- }"
 		return
 		;;
 	url.*.*)
diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index 2de1a72c09..35300a08cd 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -122,16 +122,6 @@ __gitcomp_file ()
 	compadd -f -p "${2-}" -- ${(f)1} && _ret=0
 }
 
-__gitcomp_direct_append ()
-{
-	__gitcomp_direct "$@"
-}
-
-__gitcomp_nl_append ()
-{
-	__gitcomp_nl "$@"
-}
-
 __gitcomp_file_direct ()
 {
 	__gitcomp_file "$1" ""
-- 
2.37.2.351.g9bf691b78c.dirty
Previous: Felipe ContrerasNext: Felipe Contreras
Message 18 of 52 in “completion: revamp”
  1. 00/51 completion: revampFelipe Contreras, Aug 30, 2022
  2. 01/51 test: completion add test for __git_cmd_idxFelipe Contreras, Aug 30, 2022
  3. 03/51 completion: fix __git_cmd_idx regression for zshFelipe Contreras, Aug 30, 2022
  4. 02/51 test: add zsh completion testsFelipe Contreras, Aug 30, 2022
  5. 04/51 completion: bash: trivial cleanupFelipe Contreras, Aug 30, 2022
  6. 05/51 completion: zsh: add higher-priority locationFelipe Contreras, Aug 30, 2022
  7. 09/51 completion: prompt: use generic colorsFelipe Contreras, Aug 30, 2022
  8. 07/51 zsh: simplify realpath dirname idiomFelipe Contreras, Aug 30, 2022
  9. 10/51 completion: fix for suboptions with valueFelipe Contreras, Aug 30, 2022
  10. 06/51 zsh: resolve symlink of scriptFelipe Contreras, Aug 30, 2022
  11. 08/51 test: reset environment variablesFelipe Contreras, Aug 30, 2022
  12. 11/51 completion: zsh: trivial improvementFelipe Contreras, Aug 30, 2022
  13. 12/51 completion: bash: do not modify COMP_WORDBREAKSFelipe Contreras, Aug 30, 2022
  14. 13/51 test: completion: fix currently typed wordsFelipe Contreras, Aug 30, 2022
  15. 14/51 test: completion: switch __gitcomp_nl prefix testFelipe Contreras, Aug 30, 2022
  16. 15/51 test: completion: add run_func() helperFelipe Contreras, Aug 30, 2022
  17. 16/51 completion: bash: remove non-append functionalityFelipe Contreras, Aug 30, 2022
  18. 17/51 completion: bash: get rid of _append() functionsFelipe Contreras, Aug 30, 2022
  19. 18/51 completion: bash: get rid of any non-append codeFelipe Contreras, Aug 30, 2022
  20. 19/51 completion: zsh: fix options with argumentsFelipe Contreras, Aug 30, 2022
  21. 20/51 completion: zsh: expand --git-dir file argumentFelipe Contreras, Aug 30, 2022
  22. 21/51 completion: zsh: add support for general -C optsFelipe Contreras, Aug 30, 2022
  23. 23/51 completion: zsh: add support for general -c optsFelipe Contreras, Aug 30, 2022
  24. 24/51 completion: zsh: fix extra space on foo=Felipe Contreras, Aug 30, 2022
  25. 22/51 completion: zsh: fix for undefined completionsFelipe Contreras, Aug 30, 2022
  26. 28/51 completion: simplify equal suffix checkFelipe Contreras, Aug 30, 2022
  27. 30/51 completion: simplify __gitcompFelipe Contreras, Aug 30, 2022
  28. 32/51 completion: improve __gitcomp suffix codeFelipe Contreras, Aug 30, 2022
  29. 33/51 test: completion: add missing testFelipe Contreras, Aug 30, 2022
  30. 25/51 completion: zsh: add excluded optionsFelipe Contreras, Aug 30, 2022
  31. 27/51 completion: factor out check in __gitcompFelipe Contreras, Aug 30, 2022
  32. 26/51 completion: zsh: always set compsetFelipe Contreras, Aug 30, 2022
  33. 29/51 completion: refactor __gitcompFelipe Contreras, Aug 30, 2022
  34. 31/51 completion: bash: change suffix check in __gitcompFelipe Contreras, Aug 30, 2022
  35. 36/51 completion: add __gitcomp_optsFelipe Contreras, Aug 30, 2022
  36. 37/51 completion: bash: cleanup __gitcomp* invocationsFelipe Contreras, Aug 30, 2022
  37. 34/51 completion: bash: simplify config_variable_nameFelipe Contreras, Aug 30, 2022
  38. 35/51 completion: bash: improve __gitcomp descriptionFelipe Contreras, Aug 30, 2022
  39. 38/51 completion: bash: shuffle __gitcomp functionsFelipe Contreras, Aug 30, 2022
  40. 39/51 completion: zsh: simplify __gitcomp_directFelipe Contreras, Aug 30, 2022
  41. 42/51 completion: zsh: add elements individually in __gitcomp_optsFelipe Contreras, Aug 30, 2022
  42. 43/51 completion: zsh: add __gitcompadd helperFelipe Contreras, Aug 30, 2022
  43. 40/51 completion: zsh: shuffle __gitcomp* functionsFelipe Contreras, Aug 30, 2022
  44. 45/51 completion: bash: simplify _get_comp_words_by_ref()Felipe Contreras, Aug 30, 2022
  45. 41/51 completion: zsh: fix direct quotingFelipe Contreras, Aug 30, 2022
  46. 44/51 completion: zsh: add correct removable suffixFelipe Contreras, Aug 30, 2022
  47. 48/51 completion: bash: trivial cleanupFelipe Contreras, Aug 30, 2022
  48. 47/51 completion: bash: cleanup _get_comp_words_by_ref()Felipe Contreras, Aug 30, 2022
  49. 46/51 completion: bash: refactor _get_comp_words_by_ref()Felipe Contreras, Aug 30, 2022
  50. 49/51 completion: bash: rename _get_comp_words_by_ref()Felipe Contreras, Aug 30, 2022
  51. 50/51 zsh: remove versionFelipe Contreras, Aug 30, 2022
  52. 51/51 completion: bash: trivial grammar fixFelipe Contreras, Aug 30, 2022

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.