Created
July 25, 2016 04:17
-
-
Save karuppasamy/10e7d98b8c5dffaf62484b39a9fce958 to your computer and use it in GitHub Desktop.
Git activity.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
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 [REMOTE]" | |
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 -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 | |
REMOTE=${1:-"origin"} | |
# Use newline as a field separator | |
IFS=$(echo -en "\n\b") | |
# Use tac if available, otherwise tail with the possibly-not-always-available | |
# -r flag (for reverse output) | |
TAC=$(which tac || echo 'tail -r') | |
for line in $(git for-each-ref ${GIT_OPTS} refs/remotes/${REMOTE} --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 | eval $TAC # reverse sort the output to show the newest entry last |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment