Created
June 24, 2016 09:46
-
-
Save s-leroux/7cb7424d33ba3753e907cc2553bcd1ba to your computer and use it in GitHub Desktop.
Post GIST
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
# 0. Your file name | |
FNAME=some.file | |
# 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' "${FNAME}" | awk '{ printf($0 "\\n") }') | |
# 2. Build the JSON request | |
read -r -d '' DESC <<EOF | |
{ | |
"description": "some description", | |
"public": true, | |
"files": { | |
"${FNAME}": { | |
"content": "${CONTENT}" | |
} | |
} | |
} | |
EOF | |
# 3. Use curl to send a POST request | |
# ANONYMOUS GIST : | |
# curl -X POST -d "${DESC}" "https://api.github.com/gists" | |
# REGISTERED USER | |
curl -u "${GITHUB_USERNAME}" -X POST -d "${DESC}" "https://api.github.com/gists" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code deserves a repo: https://github.com/ceremcem/create-gist (I'll hand it over to @s-leroux on request)