Skip to content

Instantly share code, notes, and snippets.

@ky0n
Last active January 29, 2023 01:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ky0n/807241772531b5571f5f1a88eae037d6 to your computer and use it in GitHub Desktop.
Save ky0n/807241772531b5571f5f1a88eae037d6 to your computer and use it in GitHub Desktop.
Show github contributions graph in terminal / shell
#!/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
@ky0n
Copy link
Author

ky0n commented Apr 18, 2022

Just change the MYGITHUB Variable. Inspired by https://gist.github.com/johngrib/6e5fe7770ede87047cbd407a456f4f8c

screenshot_contributions

@ky0n
Copy link
Author

ky0n commented Jan 29, 2023

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