How to create a gist on command line

trbvm picture trbvm · Dec 2, 2015 · Viewed 8.4k times · Source

I am trying to create a gist from bash, and I have tried many versions scripts I could get, but none are working.

This seems like a correct one, but it does not work also.

curl -X POST -d '{"public":true,"files":{"test.txt":{"content":"String file contents"}}}' https://api.github.com/gists

I have a test.txt file with content I would like to create the gist, but it won't work. It says, invalid email, if I try to add -u USER or -u USER:PASS it still won't work saying "message": "Problems parsing JSON", ..

I don't know what is wrong. the documentation does not provide much except for this line:

POST /gists as you can see, I am passing the test.txt file.

Answer

Bruno picture Bruno · Apr 27, 2019

This question is old, so I am not sure it is still relevant.

On Ubuntu (at least on 18.04), you can try the gist package, which will install the gist-paste command that you can use (given you have a git account already) as below:

1) Get a gist OAuth2 token (it will create a ~/.gist file with the token). You have to do it once only:

$ gist-paste --login

Then, you can send your files, for instance:

$ gist-paste your-file.txt
$ cat .emacs.d/init.el | gist-paste -t el

There are many options: You can send file type/description (as above second example), delete gists, open gist in browser, etc... See gist-paste(1) or try gist-paste --help.

If you already have a gist token, you don't need to run gist-paste --login, just copy your ~/.gitconfig's oauth-token to ~/.gist. For example, if you have in ~/.gitconfig:

[github]
    oauth-token = foobar123

Just create a ~/.gist file with one line containing "foobar123".

[Edit] If your distribution does not provide the package, the project page is: https://github.com/defunkt/gist