Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. set -e
  4.  
  5. GIT_OPTS="--max-count=10"
  6.  
  7. commit_id_format=$(tput setaf 3)
  8. date_format=$(tput setaf 4)
  9. author_format=$(tput setaf 2)
  10. ref_name_format=$(tput setaf 1)
  11. reset=$(tput sgr0)
  12.  
  13. function usage() {
  14. echo ""
  15. echo "git activity [-c|--count <number>] [--no-color] [--fetch]"
  16. echo ""
  17. echo " List commit logs sorted by commit date."
  18. echo ""
  19. echo "OPTIONS"
  20. echo " --fetch"
  21. echo " Fetch download objects and refs from all the remotes that are configured."
  22. echo " --no-color"
  23. echo " Turn off colored output."
  24. echo " --c | --count <number>"
  25. echo " Limit the output to <number> of entries."
  26. }
  27.  
  28. # actually parse the options and do stuff
  29. while [[ $1 = -?* ]]; do
  30. case $1 in
  31. -h|--help)
  32. usage
  33. exit 0
  34. ;;
  35. --fetch)
  36. echo "Fetch updates"
  37. git fetch -q
  38. ;;
  39. -c|--count)
  40. shift
  41. limit=${1-"10"}
  42. GIT_OPTS="--max-count=${limit}"
  43. ;;
  44. --no-color|--no-colour)
  45. commit_id_format=""
  46. date_format=""
  47. author_format=""
  48. ref_name_format=""
  49. reset=""
  50. ;;
  51. *) ;;
  52. esac
  53.  
  54. shift
  55. done
  56.  
  57. # Use newline as a field separator
  58. IFS=$(echo -en "\n\b")
  59.  
  60. for line in $(git --no-pager log --format="%ar|%h|%an|%s|%d" ${GIT_OPTS}); do
  61. fields=(`echo $line | tr "|" "\n"`)
  62. printf "${date_format}%15s${reset} ${commit_id_format}%s${reset} - ${author_format}[%s]${reset} %s${ref_name_format}%s\n" ${fields[*]}
  63. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement