bash: Add space after unique command name is completed.
[gitweb.git] / contrib / completion / git-completion.bash
index b87f96d9eadb0b99fbe3ce2c1e1c0e38b9601b13..1cf576e1e57820ed13bfa9fe583b77779b315502 100755 (executable)
@@ -61,6 +61,20 @@ __git_ps1 ()
        fi
 }
 
+__gitcomp ()
+{
+       local all c s=$'\n' IFS=' '$'\t'$'\n'
+       for c in $1; do
+               case "$c" in
+               --*=*) all="$all$c$s" ;;
+               *)     all="$all$c $s" ;;
+               esac
+       done
+       IFS=$s
+       COMPREPLY=($(compgen -W "$all" -- "${COMP_WORDS[COMP_CWORD]}"))
+       return
+}
+
 __git_heads ()
 {
        local cmd i is_hash=y dir="$(__gitdir "$1")"
@@ -235,6 +249,7 @@ __git_commands ()
        for i in $(git help -a|egrep '^ ')
        do
                case $i in
+               add--interactive) : plumbing;;
                cat-file)         : plumbing;;
                check-ref-format) : plumbing;;
                commit-tree)      : plumbing;;
@@ -358,6 +373,19 @@ _git_apply ()
        COMPREPLY=()
 }
 
+_git_add ()
+{
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       case "$cur" in
+       --*)
+               COMPREPLY=($(compgen -W "
+                       --interactive
+                       " -- "$cur"))
+               return
+       esac
+       COMPREPLY=()
+}
+
 _git_branch ()
 {
        local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -773,12 +801,12 @@ _git ()
        done
 
        if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
-               COMPREPLY=($(compgen -W "
-                       --git-dir= --version --exec-path
-                       $(__git_commands)
-                       $(__git_aliases)
-                       " -- "${COMP_WORDS[COMP_CWORD]}"))
-               return;
+               case "${COMP_WORDS[COMP_CWORD]}" in
+               --*=*) COMPREPLY=() ;;
+               --*)   __gitcomp "--git-dir= --bare --version --exec-path" ;;
+               *)     __gitcomp "$(__git_commands) $(__git_aliases)" ;;
+               esac
+               return
        fi
 
        local expansion=$(__git_aliased_command "$command")
@@ -786,6 +814,7 @@ _git ()
 
        case "$command" in
        am)          _git_am ;;
+       add)         _git_add ;;
        apply)       _git_apply ;;
        branch)      _git_branch ;;
        checkout)    _git_checkout ;;
@@ -852,6 +881,7 @@ complete -o default -o nospace -F _git_log git-whatchanged
 # included the '.exe' suffix.
 #
 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
+complete -o default            -F _git_add git-add.exe
 complete -o default            -F _git_apply git-apply.exe
 complete -o default -o nospace -F _git git.exe
 complete -o default            -F _git_branch git-branch.exe