Code

[GH-6] Make blame configurable via options from ~/.tigrc and the command line
[tig.git] / contrib / tig-completion.bash
index 3b6fd6dd2339a5f46ea8db8734e86180bf8c9bce..402e1cfc2538595f4f0d4b590b5c8b601cfbb5bd 100755 (executable)
@@ -1,7 +1,7 @@
 ##
 # bash completion support for tig
 #
-# Copyright (C) 2007 Jonas fonseca
+# Copyright (C) 2007-2010 Jonas fonseca
 # Copyright (C) 2006,2007 Shawn Pearce
 #
 # Based git's git-completion.sh: http://repo.or.cz/w/git/fastimport.git
@@ -43,7 +43,7 @@ __tigdir ()
        fi
 }
 
-tigcomp ()
+_tigcomp ()
 {
        local all c s=$'\n' IFS=' '$'\t'$'\n'
        local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -120,7 +120,7 @@ __tig_complete_file ()
                        -- "$cur"))
                ;;
        *)
-               tigcomp "$(__tig_refs)"
+               _tigcomp "$(__tig_refs)"
                ;;
        esac
 }
@@ -132,39 +132,34 @@ __tig_complete_revlist ()
        *...*)
                pfx="${cur%...*}..."
                cur="${cur#*...}"
-               tigcomp "$(__tig_refs)" "$pfx" "$cur"
+               _tigcomp "$(__tig_refs)" "$pfx" "$cur"
                ;;
        *..*)
                pfx="${cur%..*}.."
                cur="${cur#*..}"
-               tigcomp "$(__tig_refs)" "$pfx" "$cur"
+               _tigcomp "$(__tig_refs)" "$pfx" "$cur"
                ;;
        *.)
-               tigcomp "$cur."
+               _tigcomp "$cur."
                ;;
        *)
-               tigcomp "$(__tig_refs)"
+               _tigcomp "$(__tig_refs)"
                ;;
        esac
 }
 
-_tig_diff ()
-{
-       __tig_complete_file
-}
-
-_tig_log ()
+_tig_options ()
 {
        local cur="${COMP_WORDS[COMP_CWORD]}"
        case "$cur" in
        --pretty=*)
-               tigcomp "
+               _tigcomp "
                        oneline short medium full fuller email raw
                        " "" "${cur##--pretty=}"
                return
                ;;
        --*)
-               tigcomp "
+               _tigcomp "
                        --max-count= --max-age= --since= --after=
                        --min-age= --before= --until=
                        --root --not --topo-order --date-order
@@ -175,25 +170,50 @@ _tig_log ()
                        --all-match
                        --pretty= --name-status --name-only
                        --not --all
+                       --help --version
                        "
                return
                ;;
+       -*)
+               _tigcomp "-v -h"
+               return
+               ;;
        esac
        __tig_complete_revlist
 }
 
+_tig_blame ()
+{
+       local reply="" ref=HEAD cur="${COMP_WORDS[COMP_CWORD]}"
+
+       if test "$COMP_CWORD" -lt 3; then
+               reply="$(__tig_refs)"
+       else
+               ref="${COMP_WORDS[2]}"
+       fi
+
+       reply="$reply $(git --git-dir="$(__tigdir)" ls-tree "$ref" \
+                       | sed '/^100... blob /s,^.*     ,,
+                              /^040000 tree /{
+                                  s,^.*        ,,
+                                  s,$,/,
+                              }
+                              s/^.*    //')"
+       _tigcomp "$reply"
+}
+
 _tig_show ()
 {
        local cur="${COMP_WORDS[COMP_CWORD]}"
        case "$cur" in
        --pretty=*)
-               tigcomp "
+               _tigcomp "
                        oneline short medium full fuller email raw
                        " "" "${cur##--pretty=}"
                return
                ;;
        --*)
-               tigcomp "--pretty="
+               _tigcomp "--pretty="
                return
                ;;
        esac
@@ -217,20 +237,17 @@ _tig ()
        if [ $c -eq $COMP_CWORD -a -z "$command" ]; then
                case "${COMP_WORDS[COMP_CWORD]}" in
                --*=*) COMPREPLY=() ;;
-               -*)   tigcomp "
-                               --line-number= --tab-size= --version --help
-                               -b -d -h -l -S -v
-                               " ;;
-               *)    tigcomp "log diff show $(__tig_refs)" ;;
+               -*)   _tig_options ;;
+               *)    _tigcomp "blame status show $(__tig_refs)" ;;
                esac
                return
        fi
 
        case "$command" in
-       diff)   _tig_diff ;;
+       blame)  _tig_blame ;;
        show)   _tig_show ;;
-       log)    _tig_log ;;
-       *)      tigcomp "
+       status) ;;
+       *)      _tigcomp "
                        $(__tig_complete_file)
                        $(__tig_refs)
                " ;;