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

Re: [PATCH v3 0/4] completion: couple of cleanups

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 2, 2012, 19:48 UTC
Message-ID
<7v39atvwxz.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1328145320-14071-1-git-send-email-felipe.contreras@gmail.com>
Felipe Contreras <felipe.contreras@gmail.com> writes:
Show 5 quoted lines
> Felipe Contreras (4):
>   completion: be nicer with zsh
>   completion: simplify __git_remotes
>   completion: remove unused code
>   completion: simplify __gitcomp*

My understanding is that the two patches relayed by Jonathan cover the first three entries, so here is my attempt to reconstruct the last one without seeing a single bit from the v3 series ;-)

-- >8 --
From: Felipe Contreras <felipe.contreras@gmail.com>
Subject: [PATCH] completion: simplify __gitcomp and __gitcomp_nl implementations

These shell functions are written in an unnecessarily verbose way; simplify their "conditionally use $<number> after checking $# against <number>" logic by using shell's built-in conditional substitution facilities.

Also remove the first of the two assignments to IFS in __gitcomp_nl that does not have any effect.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 contrib/completion/git-completion.bash |   19 +++----------------
 1 files changed, 3 insertions(+), 16 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 8dd4e44..1ce1d6e 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -495,11 +495,8 @@ fi
 # 4: A suffix to be appended to each possible completion word (optional).
 __gitcomp ()
 {
-	local cur_="$cur"
+	local cur_="${3-$cur}"
 
-	if [ $# -gt 2 ]; then
-		cur_="$3"
-	fi
 	case "$cur_" in
 	--*=)
 		COMPREPLY=()
@@ -524,18 +521,8 @@ __gitcomp ()
 #    appended.
 __gitcomp_nl ()
 {
-	local s=$'\n' IFS=' '$'\t'$'\n'
-	local cur_="$cur" suffix=" "
-
-	if [ $# -gt 2 ]; then
-		cur_="$3"
-		if [ $# -gt 3 ]; then
-			suffix="$4"
-		fi
-	fi
-
-	IFS=$s
-	COMPREPLY=($(compgen -P "${2-}" -S "$suffix" -W "$1" -- "$cur_"))
+	local IFS=$'\n'
+	COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
 }
 
 __git_heads ()
-- 
1.7.9.172.ge26ae
Previous: Jonathan NiederNext: Jonathan Nieder
Message 32 of 38 in “completion: couple of cleanups”
  1. 0/4 completion: couple of cleanupsFelipe Contreras, Feb 2, 2012
  2. Jonathan NiederFeb 2, 2012
  3. Felipe ContrerasFeb 2, 2012
  4. Thomas RastFeb 2, 2012
  5. Jonathan NiederFeb 2, 2012
  6. Jonathan NiederFeb 2, 2012
  7. Felipe ContrerasFeb 2, 2012
  8. Junio C HamanoFeb 2, 2012
  9. Felipe ContrerasFeb 2, 2012
  10. Junio C HamanoFeb 3, 2012
  11. Felipe ContrerasFeb 3, 2012
  12. Junio C HamanoFeb 3, 2012
  13. Felipe ContrerasFeb 4, 2012
  14. [bug] blame duplicates trailing ">" in mailmapped emailsJeff King, Feb 4, 2012
  15. Felipe ContrerasFeb 4, 2012
  16. Jeff KingFeb 4, 2012
  17. Felipe ContrerasFeb 5, 2012
  18. Jeff KingFeb 5, 2012
  19. Junio C HamanoFeb 5, 2012
  20. Junio C HamanoFeb 5, 2012
  21. Jeff KingFeb 5, 2012
  22. Junio C HamanoFeb 6, 2012
  23. Jeff KingFeb 6, 2012
  24. Junio C HamanoFeb 6, 2012
  25. Junio C HamanoFeb 6, 2012
  26. Jeff KingFeb 6, 2012
  27. Felipe ContrerasFeb 6, 2012
  28. Junio C HamanoFeb 6, 2012
  29. Felipe ContrerasFeb 6, 2012
  30. Junio C HamanoFeb 5, 2012
  31. Jonathan NiederFeb 2, 2012
  32. Junio C HamanoFeb 2, 2012
  33. Jonathan NiederFeb 2, 2012
  34. Felipe ContrerasFeb 2, 2012
  35. Jonathan NiederFeb 2, 2012
  36. Felipe ContrerasFeb 2, 2012
  37. Jonathan NiederFeb 2, 2012
  38. Felipe ContrerasFeb 2, 2012

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.