GIST(1) | Gist manual | GIST(1) |
gist-paste - upload code to https://gist.github.com
The gist gem provides a gist-paste command that you can use from your terminal to upload content to https://gist.github.com/.
To read a gist and print it to STDOUT
gist-paste -r GIST_ID gist-paste -r 374130
Before you use gist-paste for the first time you will need to log in. There are two supported login flows:
This flow allows you to obtain a token by logging into GitHub in the browser and typing a verification code. This is the preferred mechanism.
gist-paste --login Requesting login parameters... Please sign in at https://github.com/login/device
and enter code: XXXX-XXXX Success! https://github.com/settings/connections/applications/4f7ec0d4eab38e74384e
The returned access_token is stored in ~/.gist and used for all future gisting. If you need to you can revoke access from https://github.com/settings/connections/applications/4f7ec0d4eab38e74384e.
This flow asks for your GitHub username and password (and 2FA code), and exchanges them for a token with the "gist" permission (your username and password are not stored). This mechanism is deprecated by GitHub, but may still work with GitHub Enterprise.
gist-paste --login Obtaining OAuth2 access_token from GitHub. GitHub username: ConradIrwin GitHub password: 2-factor auth code: Success! https://github.com/settings/tokens
This token is stored in ~/.gist and used for all future gisting. If you need to you can revoke it from https://github.com/settings/tokens, or just delete the file.
If you have a complicated authorization requirement you can manually create a token file by pasting a GitHub token with gist scope (and maybe the user:email for GitHub Enterprise) into a file called ~/.gist. You can create one from https://github.com/settings/tokens
This file should contain only the token (~40 hex characters), and to make it easier to edit, can optionally have a final newline (\n or \r\n).
For example, one way to create this file would be to run:
(umask 0077 && echo MY_SECRET_TOKEN > ~/.gist)
The umask ensures that the file is only accessible from your user account.
If you´d like gist-paste to use your locally installed GitHub Enterprise https://enterprise.github.com/, you need to export the GITHUB_URL environment variable (usually done in your ~/.bashrc).
export GITHUB_URL=http://github.internal.example.com/
Once you´ve done this and restarted your terminal (or run source ~/.bashrc), gist-paste will automatically use GitHub Enterprise instead of the public github.com
Your token for GitHub Enterprise will be stored in .gist.<protocol>.<server.name>[.<port>] (e.g. ~/.gist.http.github.internal.example.com for the GITHUB_URL example above) instead of ~/.gist.
If you have multiple servers or use Enterprise and public GitHub often, you can work around this by creating scripts that set the env var and then run gist-paste. Keep in mind that to use the public GitHub you must unset the env var. Just setting it to the public URL will not work. Use unset GITHUB_URL
If you cannot use passwords, as most Enterprise installations do, you can generate the token via the web interface and then simply save the string in the correct file. Avoid line breaks or you might see: $ gist-paste -l Error: Bad credentials
If you need more advanced features you can also pass:
NOTE: The access_token must have the gist scope and may also require the user:email scope.
If clipboard or browser integration don´t work on your platform, please file a bug or (more ideally) a pull request.
If you need to use an HTTP proxy to access the internet, export the HTTP_PROXY or http_proxy environment variable and gist-paste will use it.
Thanks to @defunkt and @indirect for writing and maintaining versions 1 through 3. Thanks to @rking and @ConradIrwin for maintaining version 4.
Licensed under the MIT license. Bug-reports, and pull requests are welcome.
August 2020 |