Code

Add bash completion for the blame subcommand
authorJonas Fonseca <fonseca@diku.dk>
Fri, 10 Oct 2008 11:43:16 +0000 (13:43 +0200)
committerJonas Fonseca <fonseca@diku.dk>
Fri, 10 Oct 2008 11:49:35 +0000 (13:49 +0200)
NEWS
contrib/tig-completion.bash

diff --git a/NEWS b/NEWS
index 0b891f9aa8b73266b2e3aea23ab82dec880c9e7e..7b9c0feeef14d64ad23338275906afd0a6942b98 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ Improvements:
 
  - Display repository references in the sorted order: tags, heads,
    tracked remotes, remotes.
+ - Add bash completion for blame.
 
 tig-0.12.1
 ----------
index 79b414bab42235a82d249e49ba24de6c52ed3b7f..40bfcfa53ad557c3303ec38db102524224910b32 100755 (executable)
@@ -182,6 +182,26 @@ _tig_options ()
        __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]}"
@@ -218,12 +238,13 @@ _tig ()
                case "${COMP_WORDS[COMP_CWORD]}" in
                --*=*) COMPREPLY=() ;;
                -*)   _tig_options ;;
-               *)    _tigcomp "status show $(__tig_refs)" ;;
+               *)    _tigcomp "blame status show $(__tig_refs)" ;;
                esac
                return
        fi
 
        case "$command" in
+       blame)  _tig_blame ;;
        show)   _tig_show ;;
        status) ;;
        *)      _tigcomp "