Skip to main content

Github search from the cli

Project description

gh-search

GitHub code search from your cli

Features

  • Uses GitHub Search API
  • Apply filters on the GitHub Search API response (eg. ignore archived repos or search for additional text in matched content)
  • View search results grouped by repo
  • Core API rate limit check (prevent accidentally consuming your entire core api quota)
  • Works with GitHub Enterprise

Installation

pip install gh-search

Usage

IMPORTANT: This tool requires that you GitHub token set on the GITHUB_TOKEN envvar (or passed to the script via the --github-token option).

Invoke with gh-search and pass a query string as the first argument. For example, to search for the string "usage" in this repo:

gh-search usage repo:janeklb/gh-search

Note that repo: is a search qualifier natively supported by the GitHub Search API.

gh-search also offers the following options

  • -a/--include-archived: include results from archived repos (default behaviour is to exclude results from archived repositories).
  • -p TEXT/--path-filter TEXT: similar to the path: search qualifier, but a bit more flexible as it does a string match on the path (rather than relying on GitHub's indexed path components). For example -p cat will show matches against a file called mycat.json whereas path:cat will not.
  • -c TEXT/--content-filter TEXT: applies a string match on the content of a search result. A bit more flexible than specifying an additional search term in the search query, tests for a string match directly on the text content rather than relying on how GitHub has indexed a file for searching.
  • -v: verbose output, print information about the repos being scanned and ignored via filters

Enterprise

If you want to search against GitHub Enterprise set the GITHUB_API_URL envvar with a URL to the v3 api endpoint. eg. GITHUB_API_URL=https://git.mycompany.net/api/v3. You can also use the --github-api-url option for this.

Developing

  • make install-dev install dev dependencies (set up your own virtual environment first)
  • make unit run unit tests
  • make lint run linters

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

gh-search-0.4.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

gh_search-0.4.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file gh-search-0.4.0.tar.gz.

File metadata

  • Download URL: gh-search-0.4.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for gh-search-0.4.0.tar.gz
Algorithm Hash digest
SHA256 0ccdf5ff32570a51c8b203e8f480165ce4117ba993d32b59c51caec29d7823b3
MD5 260e38537f01e84ccf0b0c886f532df9
BLAKE2b-256 3062d77f0d9c7cebea4a05a88eb86db9560fb8bfaf3f42fa378df1cd6231c569

See more details on using hashes here.

Provenance

File details

Details for the file gh_search-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: gh_search-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.9.1

File hashes

Hashes for gh_search-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 84a3becb3793cc3e6c44b58d389f66bcdc46dc2602119e0d6aab981c2c4a493b
MD5 5fe273cbd94102fd2bea52f49c87ea46
BLAKE2b-256 8af57c19ddae176aa5e579fd8c8f8a1e4e1625d26883cd89e57e271af01fda84

See more details on using hashes here.

Provenance

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