Skip to content

Instantly share code, notes, and snippets.

@chicagobuss
Created February 28, 2019 14:06
Show Gist options
  • Save chicagobuss/4bf11dda3a3cf4fe298c51bf4995d4d6 to your computer and use it in GitHub Desktop.
Save chicagobuss/4bf11dda3a3cf4fe298c51bf4995d4d6 to your computer and use it in GitHub Desktop.
make a gist from the shell
### how to upload to gist with bash / curl
DESC="file that I'm uploading"
FNAME="file_to_upload"
FPATH="/tmp/file_to_upload"
# 1. Somehow sanitize the file content
# Remove \r (from Windows end-of-lines),
# Replace tabs by \t
# Replace " by \"
# Replace EOL by \n
CONTENT=$(sed -e 's/\r//' -e's/\t/\\t/g' -e 's/"/\\"/g' "${FPATH}" | awk '{ printf($0 "\\n") }')
curl -X POST -H "Content-Type: application/json" -u "<username>:<github_api_key>" -d @- "https://api.github.com/gists" <<CURL_DATA
{
"description": "${DESC}",
"public": true,
"files": {
"${FNAME}": {
"content": "${CONTENT}"
}
}
}
CURL_DATA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment