Github search from the cli
Project description
gh-search
GitHub code search with full text regex filtering, from your cli.
Features
- Filters search results (eg. ignore archived repositories or search for specific text in matched content)
- Displays results grouped by
organisation/repository
- GitHub API rate limit aware (prevent accidentally consuming your entire core API quota)
- Uses GitHub's Rest API (and therefore works with GitHub Enterprise)
Installation
gh-search
is available as a python package via pypi.org and requires Python 3.6+
pip install gh-search
Authentication
A valid GitHub personal access token, with the repo
scope, is required to retrieve search results.
It can be set on a GITHUB_TOKEN
envvar or passed to the script via the --github-token
option.
Enterprise
To search GitHub Enterprise set the GITHUB_API_URL
envvar to your organisation's GitHub v3 API endpoint.
eg. GITHUB_API_URL=https://github.mycompany.net/api/v3
. You can also use the --github-api-url
option for this.
Usage
Invoke with gh-search
and pass a query string as the first argument. For example, to search for the word "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. See GitHub's searching code documentation to see what other qualifiers are available.
Example: regex content filtering
If you are searching for a specific non-alphanumeric string you can use the --regex-content-filter
(or --content-filter
) options. This must
be combined with a valid GitHub Search API query (which will produce the result set that will subsequently be filtered).
For example if you're looking for a special_var
variable being set to a value of characters beginning with 10
you could do something like:
gh-search special_var -e "special_var\\s*=\\s*10"
All available options
Usage: gh-search [OPTIONS] QUERY...
QUERY must contain at least one search term, but may also contain search qualifiers
(https://docs.github.com/en/github/searching-for-information-on-github/searching-code)
Options:
--github-token TEXT GitHub Auth Token. Will fall back on GITHUB_TOKEN envvar.
--github-api-url TEXT Override default GitHub API URL. Can also specify via GITHUB_API_URL envvar.
-p, --path-filter TEXT Exclude results whose path (or part of path) does not match this.
-c, --content-filter TEXT Exclude results whose content does not match this.
-e, --regex-content-filter TEXT
Exclude results whose content does not match this regex.
-a, --include-archived Include results from archived repos.
-l, --repos-with-matches Only the names of repos are printed. Equivalent to --output=repo-list
-o, --output TEXT Output style; one of: default, repo-list, json, yaml
-v, --verbose Verbose output.
--help Show this message and exit.
Rate Limiting
gh-search
checks your rate limits and will prompt you to continue if your search might:
- perform more than
500
core API requests - leave you with less than
10%
of your core API quota
Only the core API quota is checked because gh-search
's filters can make heavy use it. The search API quota is not checked.
Developing
make install-dev
install dev dependencies (set up your own virtual environment first)make unit
run unit testsmake lint
run linters
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file gh-search-0.7.1.tar.gz
.
File metadata
- Download URL: gh-search-0.7.1.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7939e828abac616e129d6577153dbdb0581d081a900406db390cbb65af8127b4 |
|
MD5 | 95be925f51ac82d42889c05c71a46b88 |
|
BLAKE2b-256 | 905b97f82d444da59641ef43a18ca2183911f322a97d2637f54c3b39b43062f7 |
Provenance
File details
Details for the file gh_search-0.7.1-py3-none-any.whl
.
File metadata
- Download URL: gh_search-0.7.1-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58e09d3d17b80737c40cfa41f9d84c2f2aefd1d8aa459a13d19ab6cb44b10b09 |
|
MD5 | 3154e0456ddbf0fa198013c19816ec2b |
|
BLAKE2b-256 | a9ac9994396d37cf8f68bc715ea2eeb7ce3c179f294797d8d95c78a82161b78e |