Bash completion support for remotes in .git/config.
[gitweb.git] / contrib / completion / git-completion.bash
index a3fbb9032c1849382f82a2d7f9591cbea6e0e645..5f1be46ba57c87772c1115191b7949999b7bff8f 100755 (executable)
@@ -59,12 +59,21 @@ __git_refs2 ()
 
 __git_remotes ()
 {
-       local i REVERTGLOB=$(shopt -p nullglob)
+       local i ngoff IFS=$'\n'
+       shopt -q nullglob || ngoff=1
        shopt -s nullglob
        for i in .git/remotes/*; do
                echo ${i#.git/remotes/}
        done
-       $REVERTGLOB
+       [ "$ngoff" ] && shopt -u nullglob
+       for i in $(git repo-config --list); do
+               case "$i" in
+               remote.*.url=*)
+                       i="${i#remote.}"
+                       echo "${i/.url=*/}"
+                       ;;
+               esac
+       done
 }
 
 __git_complete_file ()
@@ -103,13 +112,20 @@ __git_complete_file ()
 
 __git_aliases ()
 {
-       git repo-config --list | grep '^alias\.' \
-               | sed -e 's/^alias\.//' -e 's/=.*$//'
+       local i IFS=$'\n'
+       for i in $(git repo-config --list); do
+               case "$i" in
+               alias.*)
+                       i="${i#alias.}"
+                       echo "${i/=*/}"
+                       ;;
+               esac
+       done
 }
 
 __git_aliased_command ()
 {
-       local cmdline=$(git repo-config alias.$1)
+       local word cmdline=$(git repo-config --get "alias.$1")
        for word in $cmdline; do
                if [ "${word##-*}" ]; then
                        echo $word
@@ -309,6 +325,7 @@ _git ()
                log)         _git_log ;;
                ls-remote)   _git_ls_remote ;;
                ls-tree)     _git_ls_tree ;;
+               merge-base)  _git_merge_base ;;
                pull)        _git_pull ;;
                push)        _git_push ;;
                reset)       _git_reset ;;
@@ -342,12 +359,15 @@ complete -o default -o nospace -F _git_pull git-pull
 complete -o default -o nospace -F _git_push git-push
 complete -o default            -F _git_reset git-reset
 complete -o default            -F _git_show git-show
+complete -o default -o nospace -F _git_log git-show-branch
 complete -o default -o nospace -F _git_log git-whatchanged
 
 # The following are necessary only for Cygwin, and only are needed
 # when the user has tab-completed the executable name and consequently
 # included the '.exe' suffix.
 #
+if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
+complete -o default -o nospace -F _git git.exe
 complete -o default            -F _git_branch git-branch.exe
 complete -o default -o nospace -F _git_cat_file git-cat-file.exe
 complete -o default -o nospace -F _git_diff git-diff.exe
@@ -356,4 +376,6 @@ complete -o default -o nospace -F _git_log git-log.exe
 complete -o default -o nospace -F _git_ls_tree git-ls-tree.exe
 complete -o default            -F _git_merge_base git-merge-base.exe
 complete -o default -o nospace -F _git_push git-push.exe
+complete -o default -o nospace -F _git_log git-show-branch.exe
 complete -o default -o nospace -F _git_log git-whatchanged.exe
+fi