Use gist-paste to Save Text Files as GitHub Gists From the Command Line
March 03, 2021 • 3 min read
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!
- Install Gist following the instructions for your system. In my case is Ubuntu so:
sudo apt install gist
- Go to the tokens section in GitHub and press on “Generate new token”. Input your password in the next screen:
- Set a name for your token and make sure to check the
gistanduser:emailpermissions:
Set a name for your token like gist.
Check gist and user:email permissions.
- Copy your generated token:
- Save the token in
~/.gist. Theumaskensures that the file is only accessible from your user account:
(umask 0077 && echo MY_SECRET_TOKEN > ~/.gist)
- Check that it has been saved correctly:
cat ~/.gist
- Now we can create gists from the command line!
Note that in Ubuntu/Debian the
gistcommand is renamed togist-pasteto avoid conflicts, if you are using a different system like MacOS just replacegist-pasteforgistin the next snippet.
echo "hello gist" >> gist.txt
gist-paste gist.txt
# Returns URL of newly created gist https://gist.github.com/eb36806673aca3c63686078d584e2a2e