Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. set -e
  4.  
  5. GIT_OPTS=""
  6. OUTPUT_FILTER="cat" # no-op
  7.  
  8. commit_id_format=$(tput setaf 1)
  9. date_format=$(tput bold; tput setaf 4)
  10. author_format=$(tput setaf 2)
  11. ref_name_format=$(tput setaf 3)
  12. bold=$(tput bold)
  13. reset=$(tput sgr0)
  14.  
  15. function usage() {
  16. echo ""
  17. echo "git activity [REMOTE]"
  18. echo ""
  19. echo " See 'man git-activity' for further information"
  20. }
  21.  
  22. # actually parse the options and do stuff
  23. while [[ $1 = -?* ]]; do
  24. case $1 in
  25. -h|--help)
  26. usage
  27. exit 0
  28. ;;
  29. --fetch)
  30. echo "Fetch updates"
  31. git fetch -q
  32. ;;
  33. -c|--count)
  34. shift
  35. limit=${1-"10"}
  36. #OUTPUT_FILTER="tail -n ${limit}"
  37. GIT_OPTS="--count=${limit}"
  38. ;;
  39. --no-color|--no-colour)
  40. commit_id_format=""
  41. date_format=""
  42. author_format=""
  43. ref_name_format=""
  44. bold=""
  45. reset=""
  46. ;;
  47. *) ;;
  48. esac
  49.  
  50. shift
  51. done
  52.  
  53. REMOTE=${1:-"origin"}
  54.  
  55. # Use newline as a field separator
  56. IFS=$(echo -en "\n\b")
  57.  
  58. # Use tac if available, otherwise tail with the possibly-not-always-available
  59. # -r flag (for reverse output)
  60. TAC=$(which tac || echo 'tail -r')
  61.  
  62. for line in $(git for-each-ref ${GIT_OPTS} refs/remotes/${REMOTE} --format="%(authordate:relative)|%(objectname:short)|%(authorname)|%(refname:short)|%(subject)" --sort="-authordate"); do
  63. fields=(`echo $line | tr "|" "\n"`)
  64. printf "${date_format}%15s${reset} ${commit_id_format}%s${reset} - ${author_format}[%s]${reset} (${ref_name_format}%s${reset}): %s\n" ${fields[*]}
  65. done | eval $TAC # reverse sort the output to show the newest entry last
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement