Last active
September 24, 2020 02:21
-
-
Save streetturtle/7e0e1829a4df2e202479b54cdf9a42a3 to your computer and use it in GitHub Desktop.
Prints contribuion graph in terminal for a given user for a given number of days
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
## Usage: print-gh-contrib-graph username num_of_days | |
## | |
## username GitHub username. | |
## num_of_days Number of days in the past to print graph for. | |
## | |
function print_graph { | |
if [ "$#" -ne 2 ]; then | |
echo "Expected 2 arguments: username and a number of days" | |
exit | |
fi | |
local IFS=$'\n' | |
intensity=`curl -s https://github-contributions.now.sh/api/v1/"$1" | jq -r --arg NUM_OF_DAYS "$2" '[.contributions[] | select ( .date | strptime("%Y-%m-%d")| mktime < now)][:$NUM_OF_DAYS|tonumber]| .[].intensity'`; | |
intensity=($intensity); | |
for (( i=${#intensity[@]} - 1; i>=0; i-- )); do | |
if ((intensity[$i] == 0)); then | |
echo -en "\e[48;5;248m \e[0m" ; | |
elif ((intensity[$i] == 1)); then | |
echo -en "\e[48;5;40m \e[0m" ; | |
elif ((intensity[$i] == 2)); then | |
echo -en "\e[48;5;34m \e[0m" ; | |
elif ((intensity[$i] == 3)); then | |
echo -en "\e[48;5;28m \e[0m" ; | |
elif ((intensity[$i] == 4)); then | |
echo -en "\e[48;5;22m \e[0m" ; | |
fi | |
done ; | |
echo | |
} | |
print_graph $1 $2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prerequisite