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 <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Shawn O. Pearce committed
Feb 4, 2007 at 02:38 UTC
72e5e989b8c22dc6dd2b4f889d5d0dabf698b387
1 file changed
+20
-6
contrib/completion/git-completion.bash
+20
-6
@@ -61,6 +61,20 @@ __git_ps1 ()
61
fi
62
}
63
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
+
78
__git_heads ()
79
{
80
local cmd i is_hash=y dir="$(__gitdir "$1")"
@@ -787,12 +801,12 @@ _git ()
801
done
802
803
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
810
fi
811
812
local expansion=$(__git_aliased_command "$command")