Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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'