Skip to content

Instantly share code, notes, and snippets.

@luoling8192
Created May 16, 2026 08:40
Show Gist options
  • Select an option

  • Save luoling8192/624f1c6cfc29725cb53be03476ecaba1 to your computer and use it in GitHub Desktop.

Select an option

Save luoling8192/624f1c6cfc29725cb53be03476ecaba1 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
if [[ $# -lt 1 || -z "${1:-}" ]]; then
echo "usage: ${0##*/} <github-username>" >&2
exit 1
fi
account=$1
if ! data=$(gh api "users/$account" 2>/dev/null); then
echo "error: failed to fetch user '$account' (check gh auth status)" >&2
exit 1
fi
id=$(jq -r '.id // empty' <<<"$data")
name=$(jq -r '.name // .login // empty' <<<"$data")
if [[ -z "$id" || -z "$name" ]]; then
echo "error: user '$account' not found or response malformed" >&2
exit 1
fi
printf 'Co-authored-by: %s <%s+%s@users.noreply.github.com>\n' "$name" "$id" "$account"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment