Coder Social home page Coder Social logo

gist's Introduction

GIST

'gist' is a command line interface for working with github gists. It provides several methods for inspecting a users gists, and the ability to easily create them.

image

Requirements

Python 3.6, 3.7, 3.8, or 3.9 is required.

Installation

The preferred way to install 'gist' is from pypi.org using pip (or pip3),

$ pip install python-gist

Alternatively, you can clone the repository and install it manually,

$ pip install .

The 'share' directory contains a set of shell scripts that provide tab completion and fuzzy search for gist. There are 3 different scripts for tab-completion in bash: gist.bash, gist-fzf.bash, and gist-fzsl.bash. The first provides simple tab completion and can be enable by adding the following to your .bashrc file,

source /usr/local/share/gist/gist.bash

The other scripts, gist-fzf.bash and fist-fzsl.bash, provide fuzzy matching of gists using an ncurses interface (NB: these scripts require fzf and fzsl, respectively).

The gist.fish script provides tab completion for the fish shell, and should be copied to ~/.config/fish/completions.

The gist.zsh script provides tab completion for the zsh shell, and should be copied to ~/.zsh as _gist. If not already in your ~/.zshrc file, you should add

fpath=(${HOME}/.zsh $fpath)

To check that 'gist' is operating correctly, you can run the unit tests with,

$ make test

Note that running the unit tests requires poetry to be available on your PATH.

Getting started

'gist' requires a personal access token for authentication. To create a token, go to https://github.com/settings/tokens. The token needs to then be added to a 'gist' configuration file that should have the form,

[gist]
token: <enter token here>
editor: <path to editor>

The editor field is optional. If the default editor is specified through some other mechanism 'gist' will try to infer it. Otherwise, you can use the config file to ensure that 'gist' uses the editor you want it to use.

If the token string begins with ! the text following is interpreted as a shell command which, when executed, prints the token to stdout. For example:

[gist]
token: !gpg --decrypt github-token.gpg

The configuration file must be in one of the following,

${XDG_DATA_HOME}/gist
${HOME}/.config/gist
${HOME}/.gist

If more than one of these files exist, this is also the order of preference, i.e. a configuration that is found in the ${XDG_DATA_HOME} directory will be taken in preference to ${HOME}/.config/gist.

Also, 'gist' assumes that you have set up your github account to use SSH keys so that you can access your repositories without needing to provide a password. Here is a link on setting up SSH keys with github.

Usage

'gist' is intended to make it easy to manage and use github gists from the command line. There are several commands available:

gist create      - creates a new gist
gist edit        - edit the files in your gist
gist description - updates the description of your gist
gist list        - prints a list of your gists
gist clone       - clones a gist
gist delete      - deletes a gist or list of gists from github
gist files       - prints a list of the files in a gist
gist archive     - downloads a gist and creates a tarball
gist content     - prints the content of the gist to stdout
gist info        - prints detailed information about a gist
gist version     - prints the current version
gist help        - prints the help documentation

gist create

Most of the 'gist' commands are pretty simple and limited in what they can do. 'gist create' is a little different and offers more flexibility in how the user can create the gist.

If you have a set of existing files that you want to turn into a gist,

$ gist create "divide et impera" foo.txt bar.txt

where the quoted string is the description of the gist. Or, you may find it useful to create a gist from content on your clipboard (say, using xclip),

$ xclip -o | gist create "ipsa scientia potestas est"

Another option is to pipe the input into 'gist create' and have it automatically put the content on github,

$ echo $(cat) | gist create "credo quia absurdum est"

Finally, you can just call,

$ gist create "a posse ad esse"

which will launch your default editor (defined by the EDITOR environment variable).

In addition to creating gists using the above methods, it is also possible to encrypt a gist if you have gnupg installed. Any of the above methods can be used to create encrypted gists by simply adding the --encrypt flag to invocation. For example,

$ gist create "arcana imperii" --encrypt

will open the editor allowing you to create the content of the gist, which is then encrypted and added to github. See the Configuration section for information on how to enable gnupg support.

gist edit

You can edit your gists directly with the 'edit' command. This command will clone the gist to a temporary directory and open up the default editor (defined by the EDITOR environment variable) to edit the files in the gist. When the editor is exited the user is prompted to commit the changes, which are then pushed back to the remote.

gist description

You can update the description of your gist with the 'description' command. You need to supply the gist ID and the new description. For example -

$ gist description e1f5e95a1705cbfde144 "This is a new description"

gist list

Returns a list of your gists. The gists are returned as,

2b1823252e8433ef8682 - mathematical divagations
a485ee9ddf6828d697be - notes on defenestration
589071c7a02b1823252e + abecedarian pericombobulations

The first column is the gists unique identifier; The second column indicates whether the gist is public ('+') or private ('-'); The third column is the description in the gist, which may be empty.

gist clone

Clones a gist to the current directory. This command will clone any gist based on its unique identifier (i.e. not just the users) to the current directory.

gist delete

Deletes the specified gists from github.

gist files

Returns a list of the files in the specified gist.

gist archive

Downloads the specified gist to a temporary directory and adds it to a tarball, which is then moved to the current directory.

gist content

Writes the content of each file in the specified gist to the terminal, e.g.

$ gist content c971fca7997aed65ddc9
foo.txt:
this is foo


bar.txt:
this is bar

For each file in the gist the first line is the name of the file followed by a colon, and then the content of that file is written to the terminal.

If a filename is given, only the content of the specified filename will be printed.

$ gist content de42344a4ecb6250d6cea00d9da6d83a file1
content of file 1

If the contents of the gist is encrypted, it can be viewed in its decrypted form by adding the --decrypt flag, e.g.

$ gist content --decrypt 8fe557fb3771aa74edfd
foo.txt.asc (decrypted):
this is a secret

See the Configuration section for information on how to enable gnupg support.

gist info

This command provides a complete dump of the information about the gist as a JSON object. It is mostly useful for debugging.

gist version

Simply prints the current version.

gist help

Prints out the help documentation.

Configuration

There are several parameters that can be added to a configuration file to determine the behavior of gist. The configuration file itself is expected to be one of the following paths,

${HOME}/.gist
${HOME}/.config/gist
${XDG_DATA_HOME}/gist

The configuration file follows the .ini style. The following is an example,

[gist]
token: dde7b84d1e0edf7454ab354934b6ab36b01bf00f
editor: /usr/bin/vim
gnupg-homedir: /home/user/.gnupg
gnupg-fingerprint: 179F9650D9FC1BFE391620B4B13A7829D8DE8623
delete-tempfiles: False

The only essential field in the configuration file is the token. This is the authentication token from github that grants gist permission to access your gists. The editor is the editor to use if the EDITOR environment is not set or you wish to use a different editor. 'gnupg-homedir' is the directory where your gnupg data are stored, and 'gnupg-fingerprint' is the fingerprint of the key to use to encrypt data in your gists. Both gnupg fields are required to support encryption/decryption.

The 'delete-tempfiles' option is used when gists are created from an editor. The editor writes its contents to a temporary file, which is deleted by default. The default behavior can be overridden by using the 'delete-tempfiles' flag.

Contributors

Thank you to the following people for contributing to 'gist'!

gist's People

Contributors

brandond avatar canpolat avatar grizmin avatar jdowner avatar jq170727 avatar jsbronder avatar karanparikh avatar kbenzie avatar loiccoyle avatar rtfmoz2 avatar seriousbug avatar tctony avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gist's Issues

using library as external module

I have an app that I want to use python-gist as a module but methods produce a result for end-user and I need to use Response object in the app. for example in create method you'll return an url that I think in my case isn't useful.

What do you think?

pip install ?

why don't add the package to pypi ?

if gist name is occupied, you can use other, like python-gist

Add option to encrypt private gists

Private gist are not inaccessible to others. Sometimes it is useful to have a gist that is 'private' that you can share with a few select people. At other times, it may be information that you do not want to share with anyone. It would be nice to have an option to encrypt a gist when it is created.

Problem with get content when "utf-8 content"

it should be nice to have unicode
$ gist content d2409da1f2ad59f4a76c

'ascii' codec can't encode characters in position 4-8: ordinal not in range(128)
therefore if i try get content of "pure ASCII " file it nicely printed to stdout.
i use python 2.7.6. on ubuntu
thanks for yours efforts

Support running a command to get API token from config file

Would there be interest in supporting a command syntax in the config file to enable the collection of the GitHub API token from an encrypted source?

Git options support running commands in config options with a ! prefix. My proposal is to support a similar syntax in this tool:

[gist]
token: !gpg --decrypt github-token.gpg

I will happily contribution this change.

Show obvious error message if no working ssh key available

% gist edit c17592d5ef054e634c7dbe48be0c186f
Cloning into 'c17592d5ef054e634c7dbe48be0c186f'...
Warning: Permanently added the RSA host key for IP address '192.30.253.119' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
1519185641.230 ERROR[gist] [Errno 2] No such file or directory: 'c17592d5ef054e634c7dbe48be0c186f

gist list works perfectly

I have access rights gist, notifications, repo for my token

Remove support for python3.{3,4}

Python 3.3 is largely unused because of major problems and 3.4 is the release prior to the introduction of the async and await keywords to the language. Most distributions are dropping support of 3.4 and below in favor of later versions, so it will simplify the maintenance of this package to using only python 3.5+ going forward.

Add option to view a gist

Currently there is no option to show a gist (print in the terminal). The work around is to edit it, but this doesn't seem right somehow.

Add bug tracking link to pypi

Just noticed another package on pypi with a link back to bug tracking. I did not realize/think about that at the time. It would be really nice to have a link from pypi back to here so people can report any bugs they find.

encrypted gists

When working with unecrypted gists everything I've tested so far (create/list/delete) works just fine, sadly the same can't be said about encrypted gists:

$ echo test | gist create dummy -encrypt
{timestamp} ERROR[gist] 'html_url'

Remove support for python2.x

Python2.x is reaching it's end of life. Many packages that currently support both python 2.x and 3.x are going to be removing support for python 2.x next year (https://python3statement.org/). This package (called python-gist on pypi.org) will also be ending support for python 2.x next year.

Delete multiple gists

Currently 'gist' only supports the deletion of one gist at a time. Enable it to take multiple identifiers to delete.

Document!

Update the README to show the usage of the available commands, and provide similar information from 'gist help'

Compatibility with windows

In the send function of gist, there is a change you can make to make the request compatible with windows.

On line 168 of gist.py change it to :

`request.url = '/'.join([request.url, stem])`

This works as the original

tries to join the os path but in windows the paths are \ instead of /

Remove unnecessary packages

Currently all packages used in the normal function of 'gist' and testing are contained in the 'dependencies.txt' file. People who want to use 'gist' but run tests, should not have to install packages that they do not need.

Add option to update gist

I'm trying to use this as a pythonic replacement for https://github.com/defunkt/gist but this tool lacks the essential function to update an existing gist. When I run "gist edit " I just get an error message.

Cloning into 'f0b2f348a1508a9fa3ad3c7a8e5fd845'...
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
1533573244.774 ERROR[gist] [Errno 2] No such file or directory: 'f0b2f348a1508a9fa3ad3c7a8e5fd845'

The rest of the operations work fine and I have the token and editor configured.

I was hoping to get something like gist update <ID> <filename> that would simply use an (existing) file to update an existing Gist. I don't understand how this is not covered in this tool.

Are there any other ways I can simply update the contents of an existing Gist? Much appreciated.

Cleanup config handling

This issue has two parts. The first relates to the amount of a code in bin/gist that is devoted to managing the config, particularly in the main function. Ideally, the main function should read as a list of the actions that can be performed. Although the config-related code clearly needs to run, it is a different level of abstraction and should not obscured the actions, which are the intent of the main function.

Secondly, ConfigParser is a little painful to use and it might help to create a thin wrapper around it. It would be nice if (1) it could be treated more like a dict (since there is only one section of interest), and (2) it should provide sensible defaults for variables where it makes sense.

Add PEP8 checks to makefile

Make it easy for contributors to check the the code conforms to PEP8 and is valid in both python2 and python3.

replace python-gnupg with pyme

using python wrapping binaries is not recommended on gnupg site.
while using pyme, swig generated bindings directly in gpgme >=1.7, is.

Handle http status codes

In most cases, I saw you didn't handle HTTP status codes and HTTP Response status isn't just 200 OK. For example, in list method you didn't check the body of your response is empty or not, this implementation makes many exceptions in the application.

Thanks

Test suite fails: ImportError: No module named tests

# python setup.py test
<...skipped...>
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "setup.py", line 58, in <module>
    'Topic :: Utilities',
  File "/usr/local/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/local/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/local/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/local/lib/python2.7/site-packages/setuptools/command/test.py", line 159, in run
    self.with_project_on_sys_path(self.run_tests)
  File "/usr/local/lib/python2.7/site-packages/setuptools/command/test.py", line 140, in with_project_on_sys_path
    func()
  File "/usr/local/lib/python2.7/site-packages/setuptools/command/test.py", line 180, in run_tests
    testRunner=self._resolve_as_ep(self.test_runner),
  File "/usr/local/lib/python2.7/unittest/main.py", line 94, in __init__
    self.parseArgs(argv)
  File "/usr/local/lib/python2.7/unittest/main.py", line 149, in parseArgs
    self.createTests()
  File "/usr/local/lib/python2.7/unittest/main.py", line 158, in createTests
    self.module)
  File "/usr/local/lib/python2.7/unittest/loader.py", line 130, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/local/lib/python2.7/unittest/loader.py", line 91, in loadTestsFromName
    module = __import__('.'.join(parts_copy))
ImportError: No module named tests

[Request] Update gist (files)

I can't find a method here to update (create a new revision) a gist.

The functionality that seems to be more similar is "edit", but it seems that clones the files, open editor and push it again (if it works, because i did now a gist edit id and it doesn't works, it says: No such file or directory: 'GISTID').

I expect something that permits me update a gist with existent file or stdin info:

gist create "my gist" file1.txt file2.txt
... modify file[12].txt ...
gist update GISTID file1.txt file2.txt

Informative errors

Currently if there is a problem with the request to github, the reported error is cryptic because the code assumes success. Check responses and provide a message to help the user understand what the problem is.

Add 'url' option to 'list' command

Currently, the list command writes out the ID for each gist. Sometimes is would be convenient to have the complete URL to the gist, rather than just the ID.

Proxy

Hi there,

I can't manage to make gist work under a proxy, even by giving all the proper proxy settings through environment variables.

$ proxy gist create "" my-file
1471632135.883 ERROR[gist] HTTPSConnectionPool(host='api.github.com', port=443): Max retries exceeded with url: /gists?access_token=****** (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f9eb951d198>: Failed to establish a new connection: [Errno 111] Connection refused',))

proxy being an alias for http_proxy="http://my-proxy:8080/" https_proxy="http://my-proxy:8080/" HTTP_PROXY=$http_proxy HTTPS_PROXY=$https_proxy.

Strange error with `gist edit`

fiatjaf@spooner:~$ gist edit d2d6cebb4da2d425e8b5
Cloning into 'd2d6cebb4da2d425e8b5'...
Warning: Permanently added the RSA host key for IP address '192.30.252.142' to the list of known hosts.
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
Checking connectivity... done.
sh: 1: traceroute fiatjaf.cloudant.com: not found
On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working directory clean

The bizarre traceroute fiatjaf.cloudant.com the shows up there is in the contents of the gist itself: https://gist.github.com/fiatjaf/d2d6cebb4da2d425e8b5

Specify editor invocation in config file

Currently we use the EDITOR variable to determine the editor to use for editing gists, and pass the files to it. This is based on my use of vim. However, that probably doesn't reflect everyones usage so it would be nice to add a field to the config file that allows a user to define how their editor should be invoked. This should also support passing additional arguments to the editor as well.

Unable to load configuration file: readfp() got an unexpected keyword argument 'source'

I have a .gist file in /home. I also tried in .config/gist

⌂179% θ72° [thoraxe:~] master* 1 ± cat ~/.gist
[gist]
token: xxx

I installed gist with sudo pip install gist:

⌂142% θ72° [thoraxe:~] master* 130 ± sudo pip install gist
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip install --user` instead.
Collecting gist
  Downloading https://files.pythonhosted.org/packages/1b/28/699079a0da8469853cf81360ac40d16b1c804a01e3b70c094b529f937fcc/gist-0.0.8.tar.gz
Requirement already satisfied: requests in /usr/lib/python2.7/site-packages (from gist) (2.20.0)
Collecting argparse (from gist)
  Downloading https://files.pythonhosted.org/packages/f2/94/3af39d34be01a24a6e65433d19e107099374224905f1e0cc6bbe1fd22a2f/argparse-1.4.0-py2.py3-none-any.whl
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/lib/python2.7/site-packages (from requests->gist) (3.0.4)
Requirement already satisfied: idna<2.8,>=2.5 in /usr/lib/python2.7/site-packages (from requests->gist) (2.7)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/lib/python2.7/site-packages (from requests->gist) (1.24.3)
Installing collected packages: argparse, gist
  Running setup.py install for gist ... done
Successfully installed argparse-1.4.0 gist-0.0.8

Not sure what's going wrong...

configparser readfp() deprecated in 3.2

/Users/macdj033/Library/Python/3.7/bin/gist:295: DeprecationWarning: This method will be removed in future versions. Use 'parser.read_file()' instead.
config.readfp(fp)

Likely should get bundled with: #24

`gist list` fails with unicode gist names (probably)

fiatjaf@spooner ~> gist list
Traceback (most recent call last):
  File "/usr/local/bin/gist", line 222, in <module>
    main()
  File "/usr/local/bin/gist", line 164, in main
    line = '{} {} {}'.format( info.id, public, info.desc)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 8: ordinal not in range(128)

Gist does not account for pagination

The github API paginates the results that it returns. This means that multiple calls may need to be made in order to retrieve a complete list of a users gists. The limit is 30 which means that currently gist only returns up to 30 gists.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.