-
Notifications
You must be signed in to change notification settings - Fork 0
/
mycontribution.sh
executable file
·53 lines (46 loc) · 1.4 KB
/
mycontribution.sh
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
#!/bin/bash
username=$1
symbol=${2:-▣}
if [[ -z $username ]]; then
echo "Usage: mycontribution <username>"
exit 1
fi
declare -a months=(" J a n" " F e b " "M a r" " A p r" " M a y" " J u n" " J u l" " A u g" " S e p" " O c t" " N o v" " D e c")
currentMonth=`date +%-m`-1
months=("${months[@]:$currentMonth}" "${months[@]::$currentMonth}")
declare -a graph=($(curl -s https://github.com/"$username" | grep -oP '(?<=data-count=").*?(?=" )'))
if [[ -z "$graph" ]]; then
echo "User $username doesn't exist"
exit 1
fi
# print months
echo
for month in "${months[@]}"
do
printf "%s" "$month"
done
printf " "
printf " %s" ${months[0]}
# print contribution graph
echo
i=0
while [[ "$i" -le 6 ]]; do
for (( n="$i";n<${#graph[@]};n+=7 )); do
if [[ "${graph[$n]}" -eq 0 ]]; then
printf "\\e[38;5;252m$symbol\\e[0m|"
elif [[ "${graph[$n]}" -lt 5 ]]; then
printf "\\e[38;5;71m$symbol\\e[0m|"
elif [[ "${graph[$n]}" -lt 10 ]]; then
printf "\\e[38;5;64m$symbol\\e[0m|"
elif [[ "${graph[$n]}" -lt 20 ]]; then
printf "\\e[38;5;22m$symbol\\e[0m|"
else
printf "\\e[38;5;238m$symbol\\e[0m|"
fi
done
echo
(( i++ ))
done
echo
printf "Less \\e[38;5;252m$symbol\\e[0m|\\e[38;5;71m$symbol\\e[0m|\\e[38;5;64m$symbol\\e[0m|\\e[38;5;22m$symbol\\e[0m|\\e[38;5;238m$symbol\\e[0m More"
echo