{"thread":{"id":"14458","subject":"[PATCH] bash completion: Resolve git show ref:path<tab> losing ref: portion","startedAt":"2008-07-15T05:39:07Z","lastAt":"2008-07-15T05:52:04Z","messageCount":2,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"83363","messageId":"20080715053907.GA3254@spearce.org","threadId":"14458","inReplyTo":null,"subject":"[PATCH] bash completion: Resolve git show ref:path<tab> losing ref: portion","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-07-15T05:39:07Z","receivedAt":"2008-07-15T05:39:07Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Linus reported that the bash completion for git show often dropped\nthe ref portion of the argument (stuff before the :) when trying\nto complete a file name of a file in another branch or tag.\n\nBj?rn Steinbrink tracked it down to the gvfs completion script\nwhich comes standard on many Fedora Core based systems.  That is\nremoving : from COMP_WORDBREAKS, making readline treat the entire\nargument (including the ref) as the name that must be completed.\nWhen the git completion routines supplied a completion of just\nthe filename, readline replaced everything.\n\nSince Git users often need to use \"ref:path\" or \"ref:ref\" sort of\narguments, and expect completion support on both sides of the :\nwe really want the : in COMP_WORDBREAKS to provide a good user\nexperience.  This is also the default that ships with bash as it\ncan be useful in other contexts, such as rcp/scp.\n\nWe now try to add : back to COMP_WORDBREAKS if it has been removed\nby a script that loaded before us.  However if this doesn't work\n(as the : is stripped after we load) we fallback in the completion\nroutines to include \"ref:\" as part of the prefix for completions,\nallowing readine to fully insert the argument the user wanted.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n contrib/completion/git-completion.bash |   27 +++++++++++++++++++++++++--\n 1 files changed, 25 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex c03230a..5844804 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -45,6 +45,11 @@\n #       git@vger.kernel.org\n #\n \n+case \"$COMP_WORDBREAKS\" in\n+*:*) : great ;;\n+*)   COMP_WORDBREAKS=\"$COMP_WORDBREAKS:\"\n+esac\n+\n __gitdir ()\n {\n \tif [ -z \"$1\" ]; then\n@@ -294,6 +299,12 @@ __git_complete_file ()\n \t\t\tls=\"$ref\"\n \t\t\t;;\n \t    esac\n+\n+\t\tcase \"$COMP_WORDBREAKS\" in\n+\t\t*:*) : great ;;\n+\t\t*)   pfx=\"$ref:$pfx\" ;;\n+\t\tesac\n+\n \t\tlocal IFS=$'\\n'\n \t\tCOMPREPLY=($(compgen -P \"$pfx\" \\\n \t\t\t-W \"$(git --git-dir=\"$(__gitdir)\" ls-tree \"$ls\" \\\n@@ -700,7 +711,12 @@ _git_fetch ()\n \t*)\n \t\tcase \"$cur\" in\n \t\t*:*)\n-\t\t\t__gitcomp \"$(__git_refs)\" \"\" \"${cur#*:}\"\n+\t\t\tlocal pfx=\"\"\n+\t\t\tcase \"$COMP_WORDBREAKS\" in\n+\t\t\t*:*) : great ;;\n+\t\t\t*)   pfx=\"${cur%%:*}:\" ;;\n+\t\t\tesac\n+\t\t\t__gitcomp \"$(__git_refs)\" \"$pfx\" \"${cur#*:}\"\n \t\t\t;;\n \t\t*)\n \t\t\tlocal remote\n@@ -876,7 +892,14 @@ _git_push ()\n \t\t\tgit-push)  remote=\"${COMP_WORDS[1]}\" ;;\n \t\t\tgit)       remote=\"${COMP_WORDS[2]}\" ;;\n \t\t\tesac\n-\t\t\t__gitcomp \"$(__git_refs \"$remote\")\" \"\" \"${cur#*:}\"\n+\n+\t\t\tlocal pfx=\"\"\n+\t\t\tcase \"$COMP_WORDBREAKS\" in\n+\t\t\t*:*) : great ;;\n+\t\t\t*)   pfx=\"${cur%%:*}:\" ;;\n+\t\t\tesac\n+\n+\t\t\t__gitcomp \"$(__git_refs \"$remote\")\" \"$pfx\" \"${cur#*:}\"\n \t\t\t;;\n \t\t+*)\n \t\t\t__gitcomp \"$(__git_refs)\" + \"${cur#+}\"\n-- \n1.5.6.2.393.g45096\n"},{"id":"83364","messageId":"20080715055204.GA3337@spearce.org","threadId":"14458","inReplyTo":"20080715053907.GA3254@spearce.org","subject":"[PATCH] bash completion: Resolve git show ref:path<tab> losing ref: portion","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-07-15T05:52:04Z","receivedAt":"2008-07-15T05:52:04Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Linus reported that the bash completion for git show often dropped\nthe ref portion of the argument (stuff before the :) when trying\nto complete a file name of a file in another branch or tag.\n\nBjörn Steinbrink tracked it down to the gvfs completion script\nwhich comes standard on many Fedora Core based systems.  That is\nremoving : from COMP_WORDBREAKS, making readline treat the entire\nargument (including the ref) as the name that must be completed.\nWhen the git completion routines supplied a completion of just the\nfilename, readline replaced everything.\n\nSince Git users often need to use \"ref:path\" or \"ref:ref\" sort of\narguments, and expect completion support on both sides of the :\nwe really want the : in COMP_WORDBREAKS to provide a good user\nexperience.  This is also the default that ships with bash as it\ncan be useful in other contexts, such as rcp/scp.\n\nWe now try to add : back to COMP_WORDBREAKS if it has been removed\nby a script that loaded before us.  However if this doesn't work\n(as the : is stripped after we load) we fallback in the completion\nroutines to include \"ref:\" as part of the prefix for completions,\nallowing readine to fully insert the argument the user wanted.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n\n Second time's the charm?  The prior version had a mangled commit\n message, due to character encoding stupidity between my keyboard\n and my chair.\n\n contrib/completion/git-completion.bash |   27 +++++++++++++++++++++++++--\n 1 files changed, 25 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex c03230a..5844804 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -45,6 +45,11 @@\n #       git@vger.kernel.org\n #\n \n+case \"$COMP_WORDBREAKS\" in\n+*:*) : great ;;\n+*)   COMP_WORDBREAKS=\"$COMP_WORDBREAKS:\"\n+esac\n+\n __gitdir ()\n {\n \tif [ -z \"$1\" ]; then\n@@ -294,6 +299,12 @@ __git_complete_file ()\n \t\t\tls=\"$ref\"\n \t\t\t;;\n \t    esac\n+\n+\t\tcase \"$COMP_WORDBREAKS\" in\n+\t\t*:*) : great ;;\n+\t\t*)   pfx=\"$ref:$pfx\" ;;\n+\t\tesac\n+\n \t\tlocal IFS=$'\\n'\n \t\tCOMPREPLY=($(compgen -P \"$pfx\" \\\n \t\t\t-W \"$(git --git-dir=\"$(__gitdir)\" ls-tree \"$ls\" \\\n@@ -700,7 +711,12 @@ _git_fetch ()\n \t*)\n \t\tcase \"$cur\" in\n \t\t*:*)\n-\t\t\t__gitcomp \"$(__git_refs)\" \"\" \"${cur#*:}\"\n+\t\t\tlocal pfx=\"\"\n+\t\t\tcase \"$COMP_WORDBREAKS\" in\n+\t\t\t*:*) : great ;;\n+\t\t\t*)   pfx=\"${cur%%:*}:\" ;;\n+\t\t\tesac\n+\t\t\t__gitcomp \"$(__git_refs)\" \"$pfx\" \"${cur#*:}\"\n \t\t\t;;\n \t\t*)\n \t\t\tlocal remote\n@@ -876,7 +892,14 @@ _git_push ()\n \t\t\tgit-push)  remote=\"${COMP_WORDS[1]}\" ;;\n \t\t\tgit)       remote=\"${COMP_WORDS[2]}\" ;;\n \t\t\tesac\n-\t\t\t__gitcomp \"$(__git_refs \"$remote\")\" \"\" \"${cur#*:}\"\n+\n+\t\t\tlocal pfx=\"\"\n+\t\t\tcase \"$COMP_WORDBREAKS\" in\n+\t\t\t*:*) : great ;;\n+\t\t\t*)   pfx=\"${cur%%:*}:\" ;;\n+\t\t\tesac\n+\n+\t\t\t__gitcomp \"$(__git_refs \"$remote\")\" \"$pfx\" \"${cur#*:}\"\n \t\t\t;;\n \t\t+*)\n \t\t\t__gitcomp \"$(__git_refs)\" + \"${cur#+}\"\n-- \n1.5.6.2.393.g45096\n"}]}