|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +if [[ $# -gt 2 ]] ; then |
| 4 | + >&2 echo "Usage: $0 [fullname] [weekstart-weekend]\nExample: $0 \"John Doe\" MON-FRI" |
| 5 | + exit 1 |
| 6 | +fi |
| 7 | + |
| 8 | +# Use colors, but only if connected to a terminal, and that terminal |
| 9 | +# supports them. |
| 10 | +if which tput >/dev/null 2>&1; then |
| 11 | + ncolors=$(tput colors) |
| 12 | +fi |
| 13 | +if [[ -t 1 ]] && [[ -n "$ncolors" ]] && [[ "$ncolors" -ge 8 ]] ; then |
| 14 | + RED="$(tput setaf 1)" |
| 15 | + GREEN="$(tput setaf 2)" |
| 16 | + YELLOW="$(tput setaf 3)" |
| 17 | + BLUE="$(tput setaf 4)" |
| 18 | + BOLD="$(tput bold)" |
| 19 | + NORMAL="$(tput sgr0)" |
| 20 | + BOLD=$(tput bold) |
| 21 | + UNDERLINE=$(tput smul) |
| 22 | + NORMAL=$(tput sgr0) |
| 23 | +else |
| 24 | + RED="" |
| 25 | + GREEN="" |
| 26 | + YELLOW="" |
| 27 | + BLUE="" |
| 28 | + BOLD="" |
| 29 | + NORMAL="" |
| 30 | + BOLD="" |
| 31 | + UNDERLINE="" |
| 32 | + NORMAL="" |
| 33 | +fi |
| 34 | + |
| 35 | +# Only enable exit-on-error after the non-critical colorization stuff, |
| 36 | +# which may fail on systems lacking tput or terminfo |
| 37 | +set -e |
| 38 | + |
| 39 | +AUTHOR=${1:-"`git config user.name`"} |
| 40 | + |
| 41 | +WEEKSTART="$( cut -d '-' -f 1 <<< "$2" )"; |
| 42 | +WEEKSTART=${WEEKSTART:="Mon"} |
| 43 | + |
| 44 | +WEEKEND="$( cut -d '-' -f 2 <<< "$2" )"; |
| 45 | +WEEKEND=${WEEKEND:="Fri"} |
| 46 | + |
| 47 | +SINCE="yesterday" |
| 48 | + |
| 49 | + |
| 50 | +## In case it is the start of week, we need to |
| 51 | +## show the commits since the last weekend |
| 52 | +shopt -s nocasematch |
| 53 | +if [[ $WEEKSTART == "$(date +%a)" ]] ; then |
| 54 | + SINCE="last $WEEKEND"; |
| 55 | +fi |
| 56 | + |
| 57 | +GIT_LOG_COMMAND="git --no-pager log \ |
| 58 | + --all |
| 59 | + --no-merges |
| 60 | + --since \"$SINCE\" |
| 61 | + --author=\"$AUTHOR\" |
| 62 | + --abbrev-commit |
| 63 | + --oneline |
| 64 | + --pretty=format:'%Cred%h%Creset - %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'" |
| 65 | + |
| 66 | +## For when the command has been run in a non-repo directory |
| 67 | +if [[ ! -d ".git" ]]; then |
| 68 | + |
| 69 | + ## Iterate through all the top level directories inside |
| 70 | + ## and look for any git repositories. |
| 71 | + for DIR in */ ; do |
| 72 | + |
| 73 | + cd "$DIR" |
| 74 | + |
| 75 | + ## Show the detail only if it is a git repository |
| 76 | + if [[ -d ".git" ]] ; then |
| 77 | + GITOUT=$(eval ${GIT_LOG_COMMAND}) |
| 78 | + |
| 79 | + ## Only output if there is some activity |
| 80 | + if [[ ! -z "$GITOUT" ]] ; then |
| 81 | + echo "${BOLD}${UNDERLINE}${YELLOW}$DIR${NORMAL}" |
| 82 | + echo "$GITOUT" |
| 83 | + fi |
| 84 | + fi |
| 85 | + |
| 86 | + cd .. |
| 87 | + done |
| 88 | +else |
| 89 | + eval ${GIT_LOG_COMMAND} |
| 90 | + echo "" ## To avoid that ugly # icon representing the end of line |
| 91 | +fi |
0 commit comments