git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] completion: fix shell expansion of items
@ 2012-09-20  2:15 Felipe Contreras
  2012-09-20  1:46 ` Jeff King
  0 siblings, 1 reply; 37+ messages in thread
From: Felipe Contreras @ 2012-09-20  2:15 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Junio C Hamano, Felipe Contreras

As reported by Jeroen Meijer[1]; the current code doesn't deal properly
with items (tags, branches, etc.) that have ${} in them because they get
expaned by bash while using compgen.

A simple solution is to quote the items so they get expanded properly
(\$\{\}).

In order to achieve that I took bash-completion's quote() function,
which is rather simple, and renamed it to __git_quote() as per Jeff
King's suggestion.

Solves the original problem for me.

[1] http://article.gmane.org/gmane.comp.version-control.git/201596

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/completion/git-completion.bash |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index d743e56..5a5b5a0 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -225,6 +225,13 @@ _get_comp_words_by_ref ()
 fi
 fi
 
+# Quotes the argument for shell reuse
+__git_quote()
+{
+	local quoted=${1//\'/\'\\\'\'}
+	printf "'%s'" "$quoted"
+}
+
 # Generates completion reply with compgen, appending a space to possible
 # completion words, if necessary.
 # It accepts 1 to 4 arguments:
@@ -261,7 +268,7 @@ __gitcomp ()
 __gitcomp_nl ()
 {
 	local IFS=$'\n'
-	COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
+	COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$(__git_quote "$1")" -- "${3-$cur}"))
 }
 
 __git_heads ()
-- 
1.7.10.3

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

end of thread, other threads:[~2012-09-28 20:29 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-20  2:15 [PATCH] completion: fix shell expansion of items Felipe Contreras
2012-09-20  1:46 ` Jeff King
2012-09-20 16:52   ` Junio C Hamano
2012-09-20 18:11   ` SZEDER Gábor
2012-09-20 18:21     ` Jeff King
2012-09-20 19:38       ` Felipe Contreras
2012-09-25  4:31     ` [PATCH] Revert "completion: fix shell expansion of items" Jeff King
2012-09-25 16:03       ` Junio C Hamano
2012-09-25 22:37       ` SZEDER Gábor
2012-09-25 23:28         ` Junio C Hamano
2012-09-26 21:46         ` Jeff King
2012-09-26 21:47           ` [PATCH 1/3] t9902: add a few basic completion tests Jeff King
2012-09-26 21:51           ` [PATCH 2/3] t9902: add completion tests for "odd" filenames Jeff King
2012-09-26 21:51           ` [PATCH 3/3] completion: improve shell expansion of items Jeff King
2012-09-26 21:57             ` [PATCH 4/3] completion: quote completions we find Jeff King
2012-09-27 21:40               ` SZEDER Gábor
2012-09-27 22:31                 ` Junio C Hamano
2012-09-27 22:58                   ` SZEDER Gábor
2012-09-27  0:37             ` [PATCH 3/3] completion: improve shell expansion of items SZEDER Gábor
2012-09-27  6:28               ` Jeff King
2012-09-27  6:43                 ` Jeff King
2012-09-27 19:48                   ` Jeff King
2012-09-28 10:05                   ` SZEDER Gábor
2012-09-28 10:09                     ` [PATCH 1/5] completion: fix non-critical bugs in __gitcomp() tests SZEDER Gábor
2012-09-28 10:09                       ` [PATCH 2/5] completion: fix args of run_completion() test helper SZEDER Gábor
2012-09-28 18:04                         ` Junio C Hamano
2012-09-28 18:38                           ` SZEDER Gábor
2012-09-28 19:23                             ` Junio C Hamano
2012-09-28 19:30                               ` Jeff King
2012-09-28 19:49                                 ` Junio C Hamano
2012-09-28 19:55                                   ` Jeff King
2012-09-28 20:28                               ` SZEDER Gábor
2012-09-28 10:09                       ` [PATCH 3/5] completion: add tests for the __gitcomp_nl() completion helper function SZEDER Gábor
2012-09-28 10:09                       ` [PATCH 4/5] completion: test __gitcomp() and __gitcomp_nl() with expandable words SZEDER Gábor
2012-09-28 10:09                       ` [POC PATCH 5/5] completion: avoid compgen to fix expansion issues in __gitcomp_nl() SZEDER Gábor
2012-09-28 15:08                         ` SZEDER Gábor
2012-09-28 15:46                           ` Jeff King

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

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).