-
-
Save matthewbednarski/3094fb2966ed7b4b1ccd to your computer and use it in GitHub Desktop.
a script for publishing gists to github
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
#!/bin/sh | |
########################################### | |
# | |
# A script for publishing gists to github | |
# | |
# requires that you create a file ~/.github.token containing an personal access token for publishing gists (https://github.com/settings/tokens) | |
# | |
# usage: | |
# gist example.js all other parameters are concatenated for use as the description, other wise the filename is used as the description | |
# | |
# | |
########################################### | |
token=$( < ~/.github.token) | |
file=$1 | |
filename=$(basename $1) | |
if [[ ! -z "$2" ]]; then | |
shift | |
fi | |
desc=$@ | |
function json_escape { | |
echo -n "$( < $1)" | python -c 'import json,sys;print(json.dumps(sys.stdin.read()))' | |
} | |
data=$(echo "\ | |
{ \ | |
\"description\":\"$desc\", \ | |
\"public\":true, \ | |
\"files\": { \ | |
\"$filename\": { \ | |
\"content\": "$(json_escape $file)" \ | |
} \ | |
} \ | |
}") | |
# echo -n $data > tmp.data.json | |
# curl -X POST -H "Authorization: token $token" --data @tmp.data.json https://api.github.com/gists | |
curl -X POST -H "Authorization: token $token" --data "$data" https://api.github.com/gists |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment