Skip to main content

CLI to update local and remote files from GitHub gists

Project description

https://img.shields.io/travis/cuducos/getgist.svg?style=flat https://img.shields.io/coveralls/cuducos/getgist.svg?style=flat https://img.shields.io/codeclimate/maintainability-percentage/cuducos/getgist.svg https://img.shields.io/pypi/v/getgist.svg?style=flat https://img.shields.io/pypi/pyversions/getgist.svg?style=flat

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 .vimrc, .gitconfig, .bash_profile etc. as Gists.

I wrote this script so I could update my dotfiles with one single command: getmy .vimrc, for example — and it’s done.

Install

$ pip install getgist

GetGist works with Python 2.7+ or 3.4+.

To update just run $ pip install -U 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 upate 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.

Using OAuth authentication

Why?

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

  1. the download of private Gists

  2. the update of existing 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

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 macth 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 username

  2. Use the shortcut getmy <filename> or putmy <filename>

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

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

Thank you very much @ddboline and /u/Sean1708 for the contributions!

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

$ pip install tox
$ 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.1.3.tar.gz (9.7 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: getgist-0.1.3.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.7

File hashes

Hashes for getgist-0.1.3.tar.gz
Algorithm Hash digest
SHA256 78867e3fd937df6a57caa111dced51ec51cfb654708ec0d793ccf0c53861eafe
MD5 cbb82ba3e5b6ebd5814a0089e854a821
BLAKE2b-256 7677dd3b376f2e33534316f61fe62c579e6b3c3fce75246c1292cf7dcffd3116

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