]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Bash completion support for aliases
authorDennis Stosberg <dennis@stosberg.net>
Sat, 28 Oct 2006 12:12:20 +0000 (14:12 +0200)
committerJunio C Hamano <junkio@cox.net>
Sat, 28 Oct 2006 20:36:39 +0000 (13:36 -0700)
 - Add aliases to the list of available git commands.
 - Make completion work for aliased commands.

Signed-off-by: Dennis Stosberg <dennis@stosberg.net>
Signed-off-by: Junio C Hamano <junkio@cox.net>
contrib/completion/git-completion.bash

index d9cb17d0b2f21b6cabd78c245f4deaf23cc6b6a0..b074f4fe5779da8907e112c8d5af1ea60f120be5 100755 (executable)
@@ -101,6 +101,23 @@ __git_complete_file ()
        esac
 }
 
+__git_aliases ()
+{
+       git repo-config --list | grep '^alias\.' \
+               | sed -e 's/^alias\.//' -e 's/=.*$//'
+}
+
+__git_aliased_command ()
+{
+       local cmdline=$(git repo-config alias.$1)
+       for word in $cmdline; do
+               if [ "${word##-*}" ]; then
+                       echo $word
+                       return
+               fi
+       done
+}
+
 _git_branch ()
 {
        local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -264,10 +281,18 @@ _git ()
 {
        if [ $COMP_CWORD = 1 ]; then
                COMPREPLY=($(compgen \
-                       -W "--version $(git help -a|egrep '^ ')" \
+                       -W "--version $(git help -a|egrep '^ ') \
+                           $(__git_aliases)" \
                        -- "${COMP_WORDS[COMP_CWORD]}"))
        else
-               case "${COMP_WORDS[1]}" in
+               local command="${COMP_WORDS[1]}"
+               local expansion=$(__git_aliased_command "$command")
+
+               if [ "$expansion" ]; then
+                       command="$expansion"
+               fi
+
+               case "$command" in
                branch)      _git_branch ;;
                cat-file)    _git_cat_file ;;
                checkout)    _git_checkout ;;