Print lines matching a pattern in repositories using GitHub API

gh-grep

:octocat: Print lines matching a pattern in repositories using GitHub API

Usage

$ gh grep func.*schema.Schema --include=**/*.go --owner k1LoW --repo tbls
k1LoW/tbls:cmd/doc.go:func withDot(s *schema.Schema, c *config.Config, force bool) (e error) {
k1LoW/tbls:cmd/doc.go:func outputErExists(s *schema.Schema, path string) bool {
k1LoW/tbls:config/config.go:func (c *Config) ModifySchema(s *schema.Schema) error {
k1LoW/tbls:config/config.go:func (c *Config) MergeAdditionalData(s *schema.Schema) error {
k1LoW/tbls:config/config.go:func (c *Config) FilterTables(s *schema.Schema) error {
k1LoW/tbls:config/config.go:func (c *Config) mergeDictFromSchema(s *schema.Schema) {
k1LoW/tbls:config/config.go:func excludeTableFromSchema(name string, s *schema.Schema) error {
[...]

( Do grep the codes (**/*.go) of k1LoW/tbls with the pattern func.*schema.Schema )

$ gh grep --help
Print lines matching a pattern in repositories using GitHub API

Usage:
  gh-grep [PATTERN] [flags]

Flags:
  -e, -- strings         match pattern
      --exclude string   skip files and directories matching pattern
  -h, --help             help for gh-grep
  -i, --ignore-case      case insensitive matching
      --include string   search only files that match pattern (default "**/*")
  -n, --line-number      show line numbers
      --name-only        show only repository:filenames
      --owner string     owner
      --repo strings     repo
      --repo-only        show only repositories
      --url              show URL
  -v, --version          version for gh-grep

⚠️ Notice ⚠️

gh-grep is very slow because it does all its scanning through the GitHub API.

It is recommended to specify the --include option to get the results in a realistic time.

Examples

List base Docker images used in the Dockerfile of the project root

$ gh grep ^FROM --include=Dockerfile --owner k1LoW
k1LoW/centve:Dockerfile:FROM centos:7
k1LoW/docker-alpine-pandoc-ja:Dockerfile:FROM frolvlad/alpine-glibc
k1LoW/docker-sshd:Dockerfile:FROM docker.io/alpine:3.9
k1LoW/gh-grep:Dockerfile:FROM debian:buster-slim
k1LoW/ghdag:Dockerfile:FROM debian:buster-slim
k1LoW/ghdag-action:Dockerfile:FROM ghcr.io/k1low/ghdag:v0.16.0
k1LoW/ghput:Dockerfile:FROM alpine:3.13
k1LoW/ghput-release-action:Dockerfile:FROM ghcr.io/k1low/ghput:v0.12.0
k1LoW/github-script-ruby:Dockerfile:FROM ghcr.io/k1low/github-script-ruby-base:v1.1.0
[...]

List Actions you are using

$ gh grep uses: --include=.github/workflows/* --owner k1LoW | sed -e 's/.*uses:\s*//g' | sort | uniq -c
   9 ./
   1 EndBug/add-and-commit@v7
   2 actions/checkout@master
  10 actions/checkout@v1
  50 actions/checkout@v2
  18 actions/setup-go@v1
  21 actions/setup-go@v2
   4 aquasecurity/trivy-action@master
[...]

Open the matched lines in a browser.

$ gh grep 'ioutil\.' --include=**/*.go --owner k1LoW --repo ghput --url
https://github.com/k1LoW/ghput/blob/main/gh/gh.go#L300
https://github.com/k1LoW/ghput/blob/main/gh/gh.go#L313
$ gh grep 'ioutil\.' --include=**/*.go --owner k1LoW --repo ghput --url | xargs open

*open command only works on macOS.

Install

gh-grep can be installed as a standalone command or as a GitHub CLI extension

Install as a GitHub CLI extension

$ gh extension install k1LoW/gh-grep

Install as a standalone command

Run gh-grep instead of gh grep.

deb:

Use dpkg-i-from-url

$ export GH-GREP_VERSION=X.X.X
$ curl -L https://git.io/dpkg-i-from-url | bash -s -- https://github.com/k1LoW/gh-grep/releases/download/v$GH-GREP_VERSION/gh-grep_$GH-GREP_VERSION-1_amd64.deb

RPM:

$ export GH-GREP_VERSION=X.X.X
$ yum install https://github.com/k1LoW/gh-grep/releases/download/v$GH-GREP_VERSION/gh-grep_$GH-GREP_VERSION-1_amd64.rpm

apk:

Use apk-add-from-url

$ export GH-GREP_VERSION=X.X.X
$ curl -L https://git.io/apk-add-from-url | sh -s -- https://github.com/k1LoW/gh-grep/releases/download/v$GH-GREP_VERSION/gh-grep_$GH-GREP_VERSION-1_amd64.apk

homebrew tap:

$ brew install k1LoW/tap/gh-grep

manually:

Download binary from releases page

go get:

$ go get github.com/k1LoW/gh-grep

docker:

$ docker pull ghcr.io/k1low/gh-grep:latest
Owner
Similar Resources

Help to release a project which especially has multiple git repositories

This project aims to help to release a project which especially has multiple git repositories. Installation Install it to a Kubernetes cluster. You ca

Dec 15, 2022

generate my_github status using GitHub Actions

generate my_github status using GitHub Actions

generate my_github status using GitHub Actions

Sep 21, 2022

Auto-updating F-Droid repo using GitHub Actions

Auto-updating F-Droid repo using GitHub Actions

fdroid This repository hosts an F-Droid repo for my apps. This allows you to install and update apps very easily. How to use At first, you should inst

Dec 29, 2022

Provides a rest API that used to count how many times a certain repository of your github has been cloned.

Provides a rest API that used to count how many times a certain repository of your github has been cloned.

traffic-clones-api An apiserver for https://shields.io/endpoint. Description Provides a rest API that used to count how many times a certain repositor

Dec 19, 2021

Gitfofo - A cmdline tool utilized github api which can help you to explore your tech boundaries

Gitfofo - A cmdline tool utilized github api which can help you to explore your tech boundaries

why gitfofo gitfofo is a cmdline tool utilized github api which can help you to explore your tech boundaries, find more interest people in github. The

Nov 21, 2022

GoThanks automatically stars Go's official repository and your go.mod github dependencies, providing a simple way to say thanks to the maintainers of the modules you use and the contributors of Go itself.

GoThanks automatically stars Go's official repository and your go.mod github dependencies, providing a simple way  to say thanks to the maintainers of the modules you use and the contributors of Go itself.

Give thanks (in the form of a GitHub ★) to your fellow Go modules maintainers. About GoThanks performs the following operations Sends a star to Go's r

Dec 24, 2022

Bot to manage team members in GitHub organizations

Team manager Team manager is a utility that allows an organization owner to add or remove people from existing teams and / or assign people for GitHub

Oct 29, 2022

Generate spreadsheets based on GitHub contributions

pullsheet generates a CSV (comma separated values) & HTML output about GitHub activity across a series of repositories.

Oct 17, 2022

Stargather is fast GitHub repository stargazers information gathering tool

Stargather is fast GitHub repository stargazers information gathering tool that can scrapes: Organization, Location, Email, Twitter, Follow

Dec 12, 2022
Comments
  • Error: bufio.Scanner: token too long

    Error: bufio.Scanner: token too long

    Excellent tool! Thank you.

    I've got Error: bufio.Scanner: token too long when searching a simple phrase for a very 1st hello world try.

    I have no knowledge about go language, but it looks like people recommend bufio.Reader.ReadLine instead of bufio.NewScanner

    https://stackoverflow.com/questions/21124327/how-to-read-a-text-file-line-by-line-in-go-when-some-lines-are-long-enough-to-ca

  • Error: env GITHUB_TOKEN is not set

    Error: env GITHUB_TOKEN is not set

    In my environment gh grep throws an error "Error: env GITHUB_TOKEN is not set". Other built-in commands from gh (like gh repo) work without any error.

    $ gh version
    gh version 2.2.0 (2021-10-25)
    
    $ gh auth status
    
    github.com
      ✓ Logged in to github.com as lacolaco (***)
      ✓ Git operations for github.com configured to use https protocol.
      ✓ Token: *******************
    

    I've just executed gh extension command for installation. Are there any additional steps?

Github-org-stats - Returns the star and fork count of repositories in an organisation

github-org-stats Utility to get github star and fork count of repositories in an

Sep 27, 2022
radix: a go radix tree with nearest matching

radix implements a radix tree. The package only provides a single Tree implementation, optimized for sparse nodes.

Feb 6, 2022
A minimalist Go PDF writer in 1982 lines. Draws text, images and shapes. Helps understand the PDF format. Used in production for reports.
A minimalist Go PDF writer in 1982 lines. Draws text, images and shapes. Helps understand the PDF format. Used in production for reports.

one-file-pdf - A minimalist PDF generator in <2K lines and 1 file The main idea behind this project was: "How small can I make a PDF generator for it

Dec 11, 2022
mackerel metric plugin for count lines in log

mackerel metric plugin for count lines in log

Nov 13, 2021
Highly extensible, customizable application launcher and window switcher written in less than 300 lines of Golang and fyne
Highly extensible, customizable application launcher and window switcher written in less than 300 lines of Golang and fyne

golauncher A go application launcher A simple, highly extensible, customizable application launcher and window switcher written in less than 300 lines

Aug 21, 2022
Print debugging, but a little bit nicer

testlog Print debugging, but a little bit nicer. The use case this is primarily designed for is effectively debugging problematic, flaky tests.

Oct 11, 2021
mmdb-dump-networks - print every network in an MMDB to STDOUT

mmdb-dump-networks mmdb-dump-networks - print every network in an MMDB to STDOUT Project Description Usage Description Installation Reporting Bugs and

Oct 19, 2021
thermal print server for esc pos printers

thprint thprint is an extremely simple printing server for thermal printers connected to raspberry pis. This printing server exposes a print endpoint

Nov 4, 2021
Verify and print TPM2.0 Quotes

Verify and print TPM2.0 Quotes Signature verified Firmware Version: XXXXXXXXXXXXXX Clock: XXXXXXXXX Resetcount: 9 Restartcount: 0 Safe: 01 Nonce Incl

Apr 15, 2022
Eye - An easy-use lib for event-driven pattern

?? Eye Eye 是一个简单易用的事件驱动模式库。 Read me in English ?? 功能特性 敬请期待。。。 历史版本的特性请查看 HISTOR

Jan 17, 2022