Skip to main content

CLI to update local and remote files from GitHub Gists.

Project description

Travis CI Coveralls PyPI Version Python Version

GetGist

Easily download any file from a GitHub Gist, with one single command.

Why?

Because of reasons I do not have a dotfiles repository. I prefer to store my init.vim, .gitconfig, .bashrc etc. as Gists.

I wrote this CLI so I could update my dotfiles with one single command: getmy vim.init, for example — and it's done.

Install

$ pip install getgist

GetGist works with Python 3.6+.

To update it just run $ pip install --upgrade getgist.

Usage

Getting Gists from GitHub

Just run getgist <username> <filename>. For example:

$ getgist cuducos .vimrc
  Fetching https://api.github.com/users/cuducos/gists
  Reading https://gist.githubusercontent.com/cuducos/409fac6ac23bf515f495/raw/666d7d01a0058e4fd898ff752db66160f10a60bb/.vimrc
  Saving .vimrc
  Done!

GetGist asks you what to do when a local file (with the same name) exists. If you decide not to delete your local copy of the file, it will be renamed with extensions such as .bkp, .bkp1, .bkp2 etc.

Updating Gists at GitHub

Just run putgist <username> <filename> to update the remote Gist with the contents of the local file. It requires an OAuth token (see Using OAuth authentication below). For example:

$ putgist cuducos .vimrc
  User cuducos authenticated
  Fetching https://api.github.com/gists
  Sending contents of .vimrc to https://api.github.com/gists/409fac6ac23bf515f495
  Done!
  The URL to this Gist is: https://gist.github.com/cuducos/409fac6ac23bf515f495

GetGist asks you what to do when it finds the different files with the same name in different Gists.

Listing Gist files from GitHub

Just run lsgists <username>. For example:

$ lsgists cuducos
  Gist           File               URL
  -------------  ------------------ -------------------------
  First Gist     file.md            https://gist.github.com/…
  My Gist #2     another_file.md    https://gist.github.com/…
  My Gist #2     README.md          https://gist.github.com/…

Secret Gists (when user is authenticated) are listed with [Secret Gist] tag next to their names.

Using OAuth authentication

Why?

Add your personal access token as as environment variable to allow:

  1. downloading private gists
  2. updating existing gists
  3. listing private gists

How?

  1. Get a personal access token with permission to manage your gists from GitHub settings
  2. Set an environment variable called GETGIST_TOKEN with your personal access token

This article might help you create an environment variable in a Unix-based operational system with Bash, but feel free to search alternatives for other systems and shells.

Example

$ export GETGIST_TOKEN=whatever1234
$ getgist cuducos .vimrc
  User cuducos authenticated
  Fetching https://api.github.com/gists
  Reading https://gist.githubusercontent.com/cuducos/409fac6ac23bf515f495/raw/666d7d01a0058e4fd898ff752db66160f10a60bb/.vimrc
  Saving .vimrc
  Done!
  The URL to this Gist is: https://gist.github.com/cuducos/409fac6ac23bf515f495

This will work even if the file you are trying to download is a private gist (surely the user name has to match the GETGIST_TOKEN account).

Setting a default user

Why?

Set a default user to avoid typing your GitHub user name all the time.

How?

  1. Set an environment variable called GETGIST_USER with your GitHub user name
  2. Use the shortcut getmy <filename>, putmy <filename> or mygists

Example

$ export GETGIST_USER=cuducos
$ getmy .vimrc
  Fetching https://api.github.com/users/cuducos/gists
  Reading https://gist.githubusercontent.com/cuducos/409fac6ac23bf515f495/raw/666d7d01a0058e4fd898ff752db66160f10a60bb/.vimrc
  Saving .vimrc
  Done!
  The URL to this Gist is: https://gist.github.com/cuducos/409fac6ac23bf515f495

Contributing

We use Poetry to manage our development environment:

  1. poetry install will get you a virtualenv with all the dependencies for you
  2. poetry shell will activate this virtualenv
  3. exit deactivates this virtualenv

Feel free to report an issue, open a pull request, or drop a line.

Don't forget to format your code with Black, and to write and run tests:

$ tox

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

getgist-0.2.2.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

getgist-0.2.2-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file getgist-0.2.2.tar.gz.

File metadata

  • Download URL: getgist-0.2.2.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.4 Darwin/20.5.0

File hashes

Hashes for getgist-0.2.2.tar.gz
Algorithm Hash digest
SHA256 4cff91ebe29e84e7c76faa09bd86cd308625e52c49ddfbe3f0e0db208e69241f
MD5 a09dec0a79db1bde156eb051251dfae7
BLAKE2b-256 3a1adf1b6b23d451a4e4989deaa83adc8eb9d899f4f45107d393c8ecaf3fb711

See more details on using hashes here.

File details

Details for the file getgist-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: getgist-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.4 Darwin/20.5.0

File hashes

Hashes for getgist-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 44818b1fb6a041f3632d2456761a1a84a0d8f79e93fdc821f82cb2ad1bf95bac
MD5 24321f4acfa5e350dc56428f816bdbd3
BLAKE2b-256 90f8e3ed716c270d5c41c57b908737d9fd35ddec5a087fbb6894aa403d8db71b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page