Created
February 28, 2019 14:06
-
-
Save chicagobuss/4bf11dda3a3cf4fe298c51bf4995d4d6 to your computer and use it in GitHub Desktop.
make a gist from the shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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