Commits

Stefan Saasen committed a9bf660

Add --count|--fetch|--no-color options. Properly format the output list

  • Participants
  • Parent commits 3532a1c

Comments (0)

Files changed (1)

 
 set -e
 
-# green: 2
-# blue: 4
-# red: 1
+GIT_OPTS=""
+OUTPUT_FILTER="cat" # no-op
 
 commit_id_format=$(tput setaf 1)
 date_format=$(tput bold; tput setaf 4)
 author_format=$(tput setaf 2)
+ref_name_format=$(tput setaf 3)
 bold=$(tput bold)
 reset=$(tput sgr0)
 
+function usage() {
+    echo ""
+    echo "git activity"
+    echo ""
+    echo "  See 'man git-activity' for further information"
+}
+
+# actually parse the options and do stuff
+while [[ $1 = -?* ]]; do
+    case $1 in
+        -h|--help)
+            usage
+            exit 0
+            ;;
+        --fetch)
+            echo "Fetch updates"
+            git fetch --all -q
+            ;;
+        -c|--count)
+            shift
+            limit=${1-"10"}
+            #OUTPUT_FILTER="tail -n ${limit}"
+            GIT_OPTS="--count=${limit}"
+            ;;
+        --no-color|--no-colour)
+            commit_id_format=""
+            date_format=""
+            author_format=""
+            ref_name_format=""
+            bold=""
+            reset=""
+            ;;
+        *) ;;
+    esac
+
+shift
+done
+
+# Use newline as a field separator
+IFS=$(echo -en "\n\b")
+
+for line in $(git for-each-ref ${GIT_OPTS} refs/remotes --format="%(authordate:relative)|%(objectname:short)|%(authorname)|%(refname:short)|%(subject)" --sort="-authordate"); do
+    fields=(`echo $line | tr "|" "\n"`)
+    printf "${date_format}%15s${reset} ${commit_id_format}%s${reset} - ${author_format}[%s]${reset} (${ref_name_format}%s${reset}): %s\n" ${fields[*]}
+done | tail -r # reverse sort the output to show the newest entry last
 
-git for-each-ref refs/remotes --format="${date_format}%(authordate:relative)${reset} ${commit_id_format}%(objectname:short)${reset} - ${author_format}[%(authorname)]${reset}: %(refname:short): %(subject)" --sort=authordate