Last active
January 29, 2023 01:29
-
-
Save ky0n/807241772531b5571f5f1a88eae037d6 to your computer and use it in GitHub Desktop.
Show github contributions graph in terminal / shell
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 | |
MYGITHUB=ky0n | |
RAW=/tmp/$MYGITHUB-github | |
curl -s https://github.com/$MYGITHUB/ > $RAW | |
echo github.com/$MYGITHUB | |
CONTRIBUTIONS_PER_YEAR="$(cat /tmp/$MYGITHUB-github | pcregrep -M '[0-9]+\n*\s*+contributions\n*\s*in\n*\s*the\n*\s*last\n*\s*year')" | |
echo $CONTRIBUTIONS_PER_YEAR | |
RESULTS=$(cat $RAW | grep '<rect.*class="ContributionCalendar-day.*contribution' | awk '{match($0,/data-level="[0-9]+/);A=substr($0,RSTART,RLENGTH);sub(/.*="/,X,A);print A}') | |
LEVELS=($RESULTS) | |
COLORS=(238 28 34 41 82) | |
for i in $(seq 0 6); do | |
for j in $(seq 0 52); do | |
index=$(expr $j '*' 7 + $i + 1) | |
if [ "$index" -gt "${#LEVELS[@]}" ]; then | |
continue | |
fi | |
COLOR=${COLORS[${LEVELS[j*7+i]}]} | |
printf "\e[48;5;%dm " $COLOR; | |
printf '\e[0m'; | |
done | |
printf "\n" | |
done |
Updated the shell script to reflect recent HTML changes.
It prints the GitHub contribution graph to the terminal
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just change the MYGITHUB Variable. Inspired by https://gist.github.com/johngrib/6e5fe7770ede87047cbd407a456f4f8c