Skip to content

Tab Completion of "repo" using Github API #47

@Amar1729

Description

@Amar1729

So I wanted to be able to use gitit to open any repo but hated having to cd somewhere or try to remember another person's username and full git repo name. I've started mocking up very simple tab completion for the gitit repo subcommand - initial work is here.

I'm new to zsh tab completion so the style is really bad and needs to be cleaned a lot before a possible PR.

Currently, it:

  1. completes ONLY the command repo (I'll add the other commands soon?)
  2. waits for you to type out a username, or completes usernames from a cache file
  3. once you complete a username, it checks the cache file - if it's too old or the user isn't there, it pulls from the GitHub API (and caches the results).

Usage:

$ gitit r<TAB>
$ gitit repo

$ gitit repo peterhurford <TAB>    # note the space - this signifies a complete username
$ gitit repo peterhurford 
64or32                        loRem                         shellplyr
DMatrix.hs                    looker-lendingclub            shinyview
...

# once a user's repos have been cached, you can then tab-complete that username
$ gitit repo pet<TAB>
$ gitit repo peterhurford 
...

This is completely up to you as the author, but I'm not sure if you feel this is scope or not? There are a few problems with the current form:

  • (major) adds a shell dependency on the jq tool (this line), which I use for parsing the JSON return. This could possibly be replaced with sed or the like since we're looking for a very specific field in the JSON. Of course, completion for repo could just fail gracefully if jq isn't installed, and other commands would complete fine.
  • (minor) is it depends on the public GitHub API, which is rate-limited at 60/hour, so if you go crazy trying to poll all your favorite authors from GitHub initially it'll start failing out (currently with incomprehensible messages)
  • (minor) the API only returns at max 100 results at a time. The API includes a sort param for most recently updated, but if you're polling a user with more than 100 repos and looking for an old one, it currently won't show up in the results.
  • (minor) adds a little bit of overhead to tab completion for the repo command

Relevant to #8 and possibly #19 .

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions