How do I pipe something from the command line to a new Github gist?

Try this gem: https://github.com/defunkt/gist

Worked for me ^_^


Seems like GitHub has a simple REST API, including methods for creating Gists. Just for fun:

$ curl -X POST \
    --data-binary '{"files": {"file1.txt": {"content": "Hello, SO"}}}' \
    https://api.github.com/gists

This successfully created this Gist. I guess it's enough to get you started.


Here's a simple bash script that takes a filename and makes it a gist.

function msg() {
  echo -n '{"description":"","public":"false","files":{"file1.txt":{"content":"'
  awk '{gsub(/"/,"\\\""); printf "%s\\n",$0}' "$1"
  echo '"}}'
}

[ "$#" -ne 1 ] && echo "Syntax: gist.sh filename" && exit 1
[ ! -r "$1" ] && echo "Error: unable to read $1" && exit 2

msg "$1" | curl -v -d '@-' https://api.github.com/gists

FYI: gist replies with the post body, so if the file is big, perhaps grep just the relevant parts of the reply.

Tags:

Shell

Github

Gist