Skip to content

Instantly share code, notes, and snippets.

@mindctrl
Forked from sindresorhus/github-email.sh
Created December 27, 2013 20:41
Show Gist options
  • Save mindctrl/8152367 to your computer and use it in GitHub Desktop.
Save mindctrl/8152367 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Created by Sindre Sorhus
# Magically retrieves a GitHub users email even though it's not publicly shown
[ "$1" = "" ] && echo "usage: $0 <GitHub username> [<repo>]" && exit 1
[ "$2" = "" ] && repo=`curl "https://api.github.com/users/$1/repos?type=owner&sort=updated" -s | sed -En 's|"name": "(.+)",|\1|p' | tr -d ' ' | head -n 1` || repo=$2
curl "https://api.github.com/repos/$1/$repo/commits" -s | sed -En 's|"(email\|name)": "(.+)",?|\2|p' | tr -s ' ' | paste - - | sort -u -k 1,1
# `paste - -` remove every other linebreak
# `sort -u -k1,1` only show unique lines based on first column (email)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment