-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitmoji
executable file
·43 lines (35 loc) · 1.06 KB
/
gitmoji
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
#!/bin/bash
# gitmoji
# by Dominic Baggott
# https://github.com/evilstreak/gitmoji
# check we're in a git repo (or bail)
git status >/dev/null 2>&1
[ $? -ne 0 ] && exit 1
# check the git repo has any commits
git rev-list --all >/dev/null 2>&1
[ $? -ne 0 ] && exit 1
# look through all known commits to find the most recent by us
git_email=`git config --get user.email`
last_commit=`git rev-list --all --author=$git_email --fixed-strings --format=%at | fgrep -v commit | sort | tail -1`
# bail if we didn't find a commit
[[ -z $last_commit ]] && exit 1
# work out how long ago it was and pick an emoji
elapsed=$((`date +%s` - $last_commit))
if [ $elapsed -lt 300 ]; then # 5 minutes
emoji=😇
elif [ $elapsed -lt 1800 ]; then # 30 minutes
emoji=😄
elif [ $elapsed -lt 3600 ]; then # 1 hour
emoji=😊
elif [ $elapsed -lt 7200 ]; then # 2 hours
emoji=😌
elif [ $elapsed -lt 21600 ]; then # 6 hours
emoji=😔
elif [ $elapsed -lt 86400 ]; then # 1 day
emoji=😞
elif [ $elapsed -lt 604800 ]; then # 1 week
emoji=😢
else
emoji=😡
fi
echo -n "$emoji "