Skip to content

Instantly share code, notes, and snippets.

@jmewes
Created September 30, 2017 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmewes/30bb0d9b8f7454b93a59994b6119f232 to your computer and use it in GitHub Desktop.
Save jmewes/30bb0d9b8f7454b93a59994b6119f232 to your computer and use it in GitHub Desktop.
How to create a Gist via shell script?
#!/bin/bash
read -d '' PAYLOAD << EOF
{
"description": "$1",
"public": true,
"files": {
"notes.md": {
"content": "$2"
}
}
}
EOF
if [[ -z $GITHUB_USER ]]; then
echo "Variable GITHUB_USER not set."
exit 1
fi
if [[ -z $GITHUB_TOKEN ]]; then
echo "Variable GITHUB_TOKEN not set."
exit 1
fi
echo "$PAYLOAD" | http --auth $GITHUB_USER:$GITHUB_TOKEN --body POST https://api.github.com/gists |
jq --raw-output '.html_url'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment