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