Skip to content

Commit 72e5e98

Browse files
spearceJunio C Hamano
authored andcommitted
bash: Add space after unique command name is completed.
Because we use the nospace option for our completion function for the main 'git' wrapper bash won't automatically add a space after a unique completion has been made by the user. This has been pointed out in the past by Linus Torvalds as an undesired behavior. I agree. We have to use the nospace option to ensure path completion for a command such as `git show` works properly, but that breaks the common case of getting the space for a unique completion. So now we set IFS=$'\n' (linefeed) and add a trailing space to every possible completion option. This causes bash to insert the space when the completion is unique. Signed-off-by: Shawn O. Pearce <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8435b54 commit 72e5e98

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

contrib/completion/git-completion.bash

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ __git_ps1 ()
6161
fi
6262
}
6363

64+
__gitcomp ()
65+
{
66+
local all c s=$'\n' IFS=' '$'\t'$'\n'
67+
for c in $1; do
68+
case "$c" in
69+
--*=*) all="$all$c$s" ;;
70+
*) all="$all$c $s" ;;
71+
esac
72+
done
73+
IFS=$s
74+
COMPREPLY=($(compgen -W "$all" -- "${COMP_WORDS[COMP_CWORD]}"))
75+
return
76+
}
77+
6478
__git_heads ()
6579
{
6680
local cmd i is_hash=y dir="$(__gitdir "$1")"
@@ -787,12 +801,12 @@ _git ()
787801
done
788802

789803
if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
790-
COMPREPLY=($(compgen -W "
791-
--git-dir= --version --exec-path
792-
$(__git_commands)
793-
$(__git_aliases)
794-
" -- "${COMP_WORDS[COMP_CWORD]}"))
795-
return;
804+
case "${COMP_WORDS[COMP_CWORD]}" in
805+
--*=*) COMPREPLY=() ;;
806+
--*) __gitcomp "--git-dir= --bare --version --exec-path" ;;
807+
*) __gitcomp "$(__git_commands) $(__git_aliases)" ;;
808+
esac
809+
return
796810
fi
797811

798812
local expansion=$(__git_aliased_command "$command")

0 commit comments

Comments
 (0)