{"thread":{"id":"6663","subject":"[PATCH 4/8] bash: Add space after unique command name is completed.","startedAt":"2007-02-04T07:38:27Z","lastAt":"2007-02-04T08:13:01Z","messageCount":3,"participants":["Shawn O. Pearce","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":8},"messages":[{"id":"33539","messageId":"20070204073827.GD17603@spearce.org","threadId":"6663","inReplyTo":null,"subject":"[PATCH 4/8] bash: Add space after unique command name is completed.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-02-04T07:38:27Z","receivedAt":"2007-02-04T07:38:27Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Because we use the nospace option for our completion function for\nthe main 'git' wrapper bash won't automatically add a space after a\nunique completion has been made by the user.  This has been pointed\nout in the past by Linus Torvalds as an undesired behavior.  I agree.\n\nWe have to use the nospace option to ensure path completion for\na command such as `git show` works properly, but that breaks the\ncommon case of getting the space for a unique completion.  So now we\nset IFS=$'\\n' (linefeed) and add a trailing space to every possible\ncompletion option.  This causes bash to insert the space when the\ncompletion is unique.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n contrib/completion/git-completion.bash |   26 ++++++++++++++++++++------\n 1 files changed, 20 insertions(+), 6 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 93f2af5..1cf576e 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -61,6 +61,20 @@ __git_ps1 ()\n \tfi\n }\n \n+__gitcomp ()\n+{\n+\tlocal all c s=$'\\n' IFS=' '$'\\t'$'\\n'\n+\tfor c in $1; do\n+\t\tcase \"$c\" in\n+\t\t--*=*) all=\"$all$c$s\" ;;\n+\t\t*)     all=\"$all$c $s\" ;;\n+\t\tesac\n+\tdone\n+\tIFS=$s\n+\tCOMPREPLY=($(compgen -W \"$all\" -- \"${COMP_WORDS[COMP_CWORD]}\"))\n+\treturn\n+}\n+\n __git_heads ()\n {\n \tlocal cmd i is_hash=y dir=\"$(__gitdir \"$1\")\"\n@@ -787,12 +801,12 @@ _git ()\n \tdone\n \n \tif [ $c -eq $COMP_CWORD -a -z \"$command\" ]; then\n-\t\tCOMPREPLY=($(compgen -W \"\n-\t\t\t--git-dir= --version --exec-path\n-\t\t\t$(__git_commands)\n-\t\t\t$(__git_aliases)\n-\t\t\t\" -- \"${COMP_WORDS[COMP_CWORD]}\"))\n-\t\treturn;\n+\t\tcase \"${COMP_WORDS[COMP_CWORD]}\" in\n+\t\t--*=*) COMPREPLY=() ;;\n+\t\t--*)   __gitcomp \"--git-dir= --bare --version --exec-path\" ;;\n+\t\t*)     __gitcomp \"$(__git_commands) $(__git_aliases)\" ;;\n+\t\tesac\n+\t\treturn\n \tfi\n \n \tlocal expansion=$(__git_aliased_command \"$command\")\n-- \n1.5.0.rc3.22.g5057\n"},{"id":"33546","messageId":"7vr6t6xs3d.fsf@assigned-by-dhcp.cox.net","threadId":"6663","inReplyTo":"20070204073827.GD17603@spearce.org","subject":"Re: [PATCH 4/8] bash: Add space after unique command name is completed.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-04T08:08:38Z","receivedAt":"2007-02-04T08:08:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> writes:\n\n> +__gitcomp ()\n> +{\n> +\tlocal all c s=$'\\n' IFS=' '$'\\t'$'\\n'\n> +\tfor c in $1; do\n> +\t\tcase \"$c\" in\n> +\t\t--*=*) all=\"$all$c$s\" ;;\n> +\t\t*)     all=\"$all$c $s\" ;;\n> +\t\tesac\n> +\tdone\n> +\tIFS=$s\n> +\tCOMPREPLY=($(compgen -W \"$all\" -- \"${COMP_WORDS[COMP_CWORD]}\"))\n> +\treturn\n> +}\n> +\n\nI do not understand what is going on here.  Care to explain?\n\n (1) \"for c in $1\": because $1 is not dquoted, it is split into\n     word with IFS -- which IFS applies to this splitting?  The\n     local one you hand-define to the typical \" \\t\\n\" value?\n\n (2) when this function returns, what IFS value does the caller\n     would have?  Is the \"local\" used to avoid screwing up the\n     caller?\n"},{"id":"33548","messageId":"20070204081301.GE16766@spearce.org","threadId":"6663","inReplyTo":"7vr6t6xs3d.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 4/8] bash: Add space after unique command name is completed.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-02-04T08:13:01Z","receivedAt":"2007-02-04T08:13:01Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> \"Shawn O. Pearce\" <spearce@spearce.org> writes:\n> \n> > +__gitcomp ()\n> > +{\n> > +\tlocal all c s=$'\\n' IFS=' '$'\\t'$'\\n'\n> > +\tfor c in $1; do\n> > +\t\tcase \"$c\" in\n> > +\t\t--*=*) all=\"$all$c$s\" ;;\n> > +\t\t*)     all=\"$all$c $s\" ;;\n> > +\t\tesac\n> > +\tdone\n> > +\tIFS=$s\n> > +\tCOMPREPLY=($(compgen -W \"$all\" -- \"${COMP_WORDS[COMP_CWORD]}\"))\n> > +\treturn\n> > +}\n> > +\n> \n> I do not understand what is going on here.  Care to explain?\n> \n>  (1) \"for c in $1\": because $1 is not dquoted, it is split into\n>      word with IFS -- which IFS applies to this splitting?  The\n>      local one you hand-define to the typical \" \\t\\n\" value?\n\nCorrect.\n \n>  (2) when this function returns, what IFS value does the caller\n>      would have?  Is the \"local\" used to avoid screwing up the\n>      caller?\n> \n\nCorrect.\n\n\nBasically at the time I'm forming 'all' I want $1 split based on\nnormal splitting rules, as I'm using space, tag and LF within the\nscript in some places for the first parameter to __gitcomp.\n\nBut when I run compgen I need IFS to be just LF ($s) so that $all\nis split only on LF and not on spaces, as spaces were added to $all\nafter each unique option.  This way the trailing space is part of\nthe unique option, and bash will tack in the trailing space for me,\ndespite having -o nospace enabled.\n\n-- \nShawn.\n"}]}