{"thread":{"id":"38802","subject":"[PATCH] contrib/completion: escape the forward slash in __git_match_ctag","startedAt":"2015-03-14T13:40:39Z","lastAt":"2015-03-15T01:58:26Z","messageCount":2,"participants":["John Szakmeister","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"257676","messageId":"1426340439-7171-1-git-send-email-john@szakmeister.net","threadId":"38802","inReplyTo":null,"subject":"[PATCH] contrib/completion: escape the forward slash in __git_match_ctag","fromName":"John Szakmeister","fromEmail":"john@szakmeister.net","sentAt":"2015-03-14T13:40:39Z","receivedAt":"2015-03-14T13:40:39Z","isPatch":true,"sender":{"key":"john@szakmeister.net","avatar":"https://avatars.githubusercontent.com/u/448087?v=4"},"body":"The current definition results in an incorrect expansion of the term under zsh.\nFor instance \"/^${1////\\\\/}/\" under zsh with the argument \"hi\" results in:\n    /^/\\/h/\\/i/\n\nThis results in an output similar to this when trying to complete `git grep\nchartab` under zsh:\n\n    :: git grep chartabawk: cmd. line:1: /^/\\/c/\\/h/\\/a/\\/r/\\/t/\\/a/\\/b/ { print $1 }\n    awk: cmd. line:1:    ^ backslash not last character on line\n    awk: cmd. line:1: /^/\\/c/\\/h/\\/a/\\/r/\\/t/\\/a/\\/b/ { print $1 }\n    awk: cmd. line:1:    ^ syntax error\n\nLeaving the prompt in a goofy state until the user hits a key.\n\nEscaping the literal / in the parameter expansion (using \"/^${1//\\//\\\\/}/\")\nresults in:\n    /^chartab/\n\nallowing the completion to work correctly.\n\nThis formulation also works under bash.\n\nSigned-off-by: John Szakmeister <john@szakmeister.net>\n---\n\nI've been bit by this bug quite a bit, but didn't have time to track it down\nuntil today.  I hope the proposed solution is acceptable.\n\n-John\n\n contrib/completion/git-completion.bash | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex c21190d..a899234 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1305,7 +1305,7 @@ _git_gitk ()\n }\n \n __git_match_ctag() {\n-\tawk \"/^${1////\\\\/}/ { print \\$1 }\" \"$2\"\n+\tawk \"/^${1//\\//\\\\/}/ { print \\$1 }\" \"$2\"\n }\n \n _git_grep ()\n-- \n2.3.1\n"},{"id":"257702","messageId":"xmqq7fujvx6l.fsf@gitster.dls.corp.google.com","threadId":"38802","inReplyTo":"1426340439-7171-1-git-send-email-john@szakmeister.net","subject":"Re: [PATCH] contrib/completion: escape the forward slash in __git_match_ctag","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-03-15T01:58:26Z","receivedAt":"2015-03-15T01:58:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"John Szakmeister <john@szakmeister.net> writes:\n\n> The current definition results in an incorrect expansion of the term under zsh.\n> For instance \"/^${1////\\\\/}/\" under zsh with the argument \"hi\" results in:\n>     /^/\\/h/\\/i/\n>\n> This results in an output similar to this when trying to complete `git grep\n> chartab` under zsh:\n>\n>     :: git grep chartabawk: cmd. line:1: /^/\\/c/\\/h/\\/a/\\/r/\\/t/\\/a/\\/b/ { print $1 }\n>     awk: cmd. line:1:    ^ backslash not last character on line\n>     awk: cmd. line:1: /^/\\/c/\\/h/\\/a/\\/r/\\/t/\\/a/\\/b/ { print $1 }\n>     awk: cmd. line:1:    ^ syntax error\n>\n> Leaving the prompt in a goofy state until the user hits a key.\n>\n> Escaping the literal / in the parameter expansion (using \"/^${1//\\//\\\\/}/\")\n> results in:\n>     /^chartab/\n>\n> allowing the completion to work correctly.\n>\n> This formulation also works under bash.\n>\n> Signed-off-by: John Szakmeister <john@szakmeister.net>\n> ---\n>\n> I've been bit by this bug quite a bit, but didn't have time to track it down\n> until today.  I hope the proposed solution is acceptable.\n>\n>  contrib/completion/git-completion.bash | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index c21190d..a899234 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -1305,7 +1305,7 @@ _git_gitk ()\n>  }\n>  \n>  __git_match_ctag() {\n> -\tawk \"/^${1////\\\\/}/ { print \\$1 }\" \"$2\"\n> +\tawk \"/^${1//\\//\\\\/}/ { print \\$1 }\" \"$2\"\n\nThe updated pattern look sensible to me. / to start the pattern\npart, extra / to say \"repeatedly replace all\", \\/ to say \"a single\nslash is what is to be replaced, / to say \"here is where the pattern\nends\", and then \\\\/ to say \"replace with backslash-slash\".\n\nIn fact, I have to suspect that the original working by pure\naccident or a bug.\n\nThanks.\n\n>  }\n>  \n>  _git_grep ()\n"}]}