Skip to content

Instantly share code, notes, and snippets.

@matthewbednarski
Last active August 29, 2015 14:27
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/78e4537f24dd688daa10 to your computer and use it in GitHub Desktop.
Save matthewbednarski/78e4537f24dd688daa10 to your computer and use it in GitHub Desktop.
a script for publishing gists; depends on curl, python anad jq. it requires that the github authorization token be saved at ~/.github.gist.token
#!/bin/sh
###########################################
#
# A script for publishing gists to github
#
# requires that you create a file ~/.github.gist.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=$(jq -r .token ~/.github.gist.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