Use gist-paste to Save Text Files as GitHub Gists From the Command Line

OMBD #7: A quick tip to save time on saving and sharing documents

Jon Portella
Level Up Coding

--

Welcome to issue #7 of One Minute Better Developer, where you become a more successful software developer by reading short nuggets of knowledge, one minute at a time.

⏮️ 🔛 ⏭️

Illustration by my buddy Loor Nicolas

THE PROBLEM

You are saving Github Gists often but you spend too much time on their UI.

A SOLUTION

Let’s do it from our CLI!

  1. Install Gist following the instructions for your system. In my case is Ubuntu so:
sudo apt install gist

2. Go to the tokens section in GitHub and press on “Generate new token”. Input your password in the next screen:

Tokens section in GitHub.

3. Set a name for your token and make sure to check the gist and user:email permissions:

Set a name for your token like gist.
Check gist and user:email permissions.

4. Copy your generated token:

Generated token.

5. Save the token in ~/.gist. The umask ensures that the file is only accessible from your user account:

(umask 0077 && echo MY_SECRET_TOKEN > ~/.gist)

6. Check that it has been saved correctly:

cat ~/.gist

7. Now we can create gists from the command line!

Note that in Ubuntu/Debian the gist command is renamed to gist-paste to avoid conflicts, if you are using a different system like MacOS just replace gist-paste for gist in the next snippet.

echo "hello gist" >> gist.txt
gist-paste gist.txt
# Returns URL of newly created gist https://gist.github.com/eb36806673aca3c63686078d584e2a2e

--

--

Software Engineer @ Pinterest - Teacher, maker, and general things do-er. - https://www.linkedin.com/in/jonportella/ - Toronto, Canada