Package: gh-search
gh-searchGitHub code search with full text regex filtering, from your cli.FeaturesFilters search results (eg. ignore archived repositories or search for specific text in matched content)Displays results grouped byorganisation/repositoryGitHub API rate limit aware (prevent accidentally consuming your entire core API quota)Uses GitHub'sRest API(and therefore works with GitHub Enterprise)Installationgh-searchis available as a python package viapypi.organd requires Python 3.7+pipinstallgh-searchAuthenticationA valid GitHub personal access token, with thereposcope, is required to retrieve search results.
It can be set on aGITHUB_TOKENenvvar or passed to the script via the--github-tokenoption.EnterpriseTo search GitHub Enterprise set theGITHUB_API_URLenvvar 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-urloption for this.UsageInvoke withgh-searchand pass a query string as the first argument. For example, to search for the word "usage" in this repo:gh-searchusagerepo:janeklb/gh-searchNote thatrepo:is a search qualifier natively supported by the GitHub Search API. See GitHub'ssearching codedocumentation to see what other qualifiers are available.Example: regex content filteringIf you are searching for a specific non-alphanumeric string you can use the--regex-content-filter(or--content-filter) options. Thismustbe 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 aspecial_varvariable being set to a value  of characters beginning with10you could do something like:gh-searchspecial_var-e"special_var\\s*=\\s*10"All available optionsUsage: 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.Saving default configuration values to diskDefault values for options can specified via a config file. Location of this file is based onclick.get_app_dir, withgh-searchas theapp_name(eg.~/Library/Application\ Support/gh-search/configon MacOS).
You'll see the exact file location printed out next to the help text of the--configofgh-search --help(or if you run with the--verboseflag).The option names must be converted to snake_case as perclick's parameter naming.For example, in order set a default--github-tokenand--github-api-urlyou would write the
following to your config file (replacing<PLACE HOLDERS>accordingly):github_token="<YOUR TOKEN>"
github_api_url="<THE API URL>"Rate Limitinggh-searchchecks yourrate limitsand will prompt you to continue if your search might:perform more than500core API requestsleave you with less than10%of your core API quotaOnly thecoreAPI quota is checked becausegh-search's filters can make heavy use it. ThesearchAPI quota isnotchecked.Developingmake install-devinstall dev dependencies (set up your own virtual environment first)make unitrun unit testsmake lintrun linters