GitHub contributions graph in a Terminal Widget using sunset theme

Script

GitHub Contributions Graph

by Brett Terpstra

The contrib service at https://brettterpstra.com/contrib renders a PNG of a GitHub user's contribution activity. Point --image at the generate URL and tune query parameters there.

Use launchd to run this script at the beginning of each week to update the chart.

Script (github-contributions-graph.sh)

#!/usr/bin/env bash
# Updates a Terminal Widget (--target github) with a contrib graph PNG.
set -euo pipefail

GITHUB_USERNAME="ttscoff"

widget-github() {
  local contrib_root="https://brettterpstra.com/contrib"
  local graph_url="${contrib_root}/generate?username=${GITHUB_USERNAME}&months=5&theme=sunset&width=600&caption_year=0&caption_month=0&caption_day=0&download=0"

  terminal-widget --target github --image "${graph_url}" --padding 0 --bg 1d1128 --full-width "$@"
}

widget-github

Download script

Running in the background with launchd

Suggested interval: 7 days (StartInterval = 604800 seconds).

Save the script from this recipe to ~/bin/github-contributions-graph.sh, then create a Launch Agent plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>com.terminalwidget.github-contributions-graph</string>
  <key>ProgramArguments</key>
  <array>
    <string>/bin/bash</string>
    <string>~/bin/github-contributions-graph.sh</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>StartInterval</key>
  <integer>604800</integer>
  <key>StandardOutPath</key>
  <string>/tmp/com.terminalwidget.github-contributions-graph.log</string>
  <key>StandardErrorPath</key>
  <string>/tmp/com.terminalwidget.github-contributions-graph.err</string>
</dict>
</plist>

From Terminal:

mkdir -p ~/bin ~/Library/LaunchAgents
# Save your script to ~/bin/github-contributions-graph.sh
cat > ~/Library/LaunchAgents/com.terminalwidget.github-contributions-graph.plist <<'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>com.terminalwidget.github-contributions-graph</string>
  <key>ProgramArguments</key>
  <array>
    <string>/bin/bash</string>
    <string>~/bin/github-contributions-graph.sh</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>StartInterval</key>
  <integer>604800</integer>
  <key>StandardOutPath</key>
  <string>/tmp/com.terminalwidget.github-contributions-graph.log</string>
  <key>StandardErrorPath</key>
  <string>/tmp/com.terminalwidget.github-contributions-graph.err</string>
</dict>
</plist>
EOF
launchctl bootstrap "gui/$(id -u)" ~/Library/LaunchAgents/com.terminalwidget.github-contributions-graph.plist

For a GUI editor and troubleshooting, see LaunchControl from soma-zone.

← All recipes