Skip to content

Instantly share code, notes, and snippets.

@matthewbednarski
Created August 18, 2015 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewbednarski/3094fb2966ed7b4b1ccd to your computer and use it in GitHub Desktop.
Save matthewbednarski/3094fb2966ed7b4b1ccd to your computer and use it in GitHub Desktop.
a script for publishing gists to github
#!/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