]> git.ipfire.org Git - thirdparty/git.git/blobdiff - contrib/completion/git-completion.bash
Bash completion support for remotes in .git/config.
[thirdparty/git.git] / contrib / completion / git-completion.bash
index b074f4fe5779da8907e112c8d5af1ea60f120be5..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
@@ -271,6 +287,13 @@ _git_push ()
        esac
 }
 
+_git_reset ()
+{
+       local cur="${COMP_WORDS[COMP_CWORD]}"
+       local opt="--mixed --hard --soft"
+       COMPREPLY=($(compgen -W "$opt $(__git_refs .)" -- "$cur"))
+}
+
 _git_show ()
 {
        local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -302,8 +325,10 @@ _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 ;;
                show)        _git_show ;;
                show-branch) _git_log ;;
                whatchanged) _git_log ;;
@@ -332,13 +357,18 @@ complete -o default -o nospace -F _git_ls_tree git-ls-tree
 complete -o default            -F _git_merge_base git-merge-base
 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
 complete -o default -o nospace -F _git_diff_tree git-diff-tree.exe
@@ -346,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