Last active
August 29, 2015 14:11
-
-
Save likejazz/535fa13bfea0e670e194 to your computer and use it in GitHub Desktop.
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="--max-count=10" | |
commit_id_format=$(tput setaf 3) | |
date_format=$(tput setaf 4) | |
author_format=$(tput setaf 2) | |
ref_name_format=$(tput setaf 1) | |
reset=$(tput sgr0) | |
function usage() { | |
echo "" | |
echo "git activity [-c|--count <number>] [--no-color] [--fetch]" | |
echo "" | |
echo " List commit logs sorted by commit date." | |
echo "" | |
echo "OPTIONS" | |
echo " --fetch" | |
echo " Fetch download objects and refs from all the remotes that are configured." | |
echo " --no-color" | |
echo " Turn off colored output." | |
echo " --c | --count <number>" | |
echo " Limit the output to <number> of entries." | |
} | |
# 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"} | |
GIT_OPTS="--max-count=${limit}" | |
;; | |
--no-color|--no-colour) | |
commit_id_format="" | |
date_format="" | |
author_format="" | |
ref_name_format="" | |
reset="" | |
;; | |
*) ;; | |
esac | |
shift | |
done | |
# Use newline as a field separator | |
IFS=$(echo -en "\n\b") | |
for line in $(git --no-pager log --format="%ar|%h|%an|%s|%d" ${GIT_OPTS}); do | |
fields=(`echo $line | tr "|" "\n"`) | |
printf "${date_format}%15s${reset} ${commit_id_format}%s${reset} - ${author_format}[%s]${reset} %s${ref_name_format}%s\n" ${fields[*]} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment