From 778306e405b416d8073652c535777f2de5fc68ad Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 14 Jul 2008 00:22:03 +0000 Subject: bash completion: Append space after file names have been completed When completing `git show origin/maint:Makef` we should add a space after the filename has been completed, so that the user can immediately begin the next argument. I also added a special case for the symlink variant so we treat it just like a normal blob, as there are no items below it in the Git tree structure. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 821c9a7..0a3bea4 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -294,9 +294,17 @@ __git_complete_file () ls="$ref" ;; esac + local IFS=$'\n' COMPREPLY=($(compgen -P "$pfx" \ -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \ - | sed '/^100... blob /s,^.* ,, + | sed '/^100... blob /{ + s,^.* ,, + s,$, , + } + /^120000 blob /{ + s,^.* ,, + s,$, , + } /^040000 tree /{ s,^.* ,, s,$,/, -- cgit v0.10.2-6-g49f6 From db8a9ff03831a26aa8bfad8bb026b90739d684ec Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 15 Jul 2008 05:52:04 +0000 Subject: bash completion: Resolve git show ref:path losing ref: portion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Linus reported that the bash completion for git show often dropped the ref portion of the argument (stuff before the :) when trying to complete a file name of a file in another branch or tag. Björn Steinbrink tracked it down to the gvfs completion script which comes standard on many Fedora Core based systems. That is removing : from COMP_WORDBREAKS, making readline treat the entire argument (including the ref) as the name that must be completed. When the git completion routines supplied a completion of just the filename, readline replaced everything. Since Git users often need to use "ref:path" or "ref:ref" sort of arguments, and expect completion support on both sides of the : we really want the : in COMP_WORDBREAKS to provide a good user experience. This is also the default that ships with bash as it can be useful in other contexts, such as rcp/scp. We now try to add : back to COMP_WORDBREAKS if it has been removed by a script that loaded before us. However if this doesn't work (as the : is stripped after we load) we fallback in the completion routines to include "ref:" as part of the prefix for completions, allowing readine to fully insert the argument the user wanted. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 0a3bea4..72f02f2 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -45,6 +45,11 @@ # git@vger.kernel.org # +case "$COMP_WORDBREAKS" in +*:*) : great ;; +*) COMP_WORDBREAKS="$COMP_WORDBREAKS:" +esac + __gitdir () { if [ -z "$1" ]; then @@ -294,6 +299,12 @@ __git_complete_file () ls="$ref" ;; esac + + case "$COMP_WORDBREAKS" in + *:*) : great ;; + *) pfx="$ref:$pfx" ;; + esac + local IFS=$'\n' COMPREPLY=($(compgen -P "$pfx" \ -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \ @@ -700,7 +711,12 @@ _git_fetch () *) case "$cur" in *:*) - __gitcomp "$(__git_refs)" "" "${cur#*:}" + local pfx="" + case "$COMP_WORDBREAKS" in + *:*) : great ;; + *) pfx="${cur%%:*}:" ;; + esac + __gitcomp "$(__git_refs)" "$pfx" "${cur#*:}" ;; *) local remote @@ -873,7 +889,14 @@ _git_push () git-push) remote="${COMP_WORDS[1]}" ;; git) remote="${COMP_WORDS[2]}" ;; esac - __gitcomp "$(__git_refs "$remote")" "" "${cur#*:}" + + local pfx="" + case "$COMP_WORDBREAKS" in + *:*) : great ;; + *) pfx="${cur%%:*}:" ;; + esac + + __gitcomp "$(__git_refs "$remote")" "$pfx" "${cur#*:}" ;; +*) __gitcomp "$(__git_refs)" + "${cur#+}" -- cgit v0.10.2-6-g49f6