Recursive grep written in Go, for everyday ease of use.
Go to file
Laurence Withers 294a41b736 Flesh out README 2023-07-07 11:50:00 +01:00
.gitignore Very early work in progress 2023-05-11 23:30:43 +01:00
LICENSE Very early work in progress 2023-05-11 23:30:43 +01:00
README.md Flesh out README 2023-07-07 11:50:00 +01:00
display.go Add some possible TODO items 2023-05-13 12:47:52 +01:00
file.go Move printedFull closer to its use, document 2023-07-07 11:21:41 +01:00
go.mod Glob matching for exclude 2023-05-13 12:45:12 +01:00
go.sum Glob matching for exclude 2023-05-13 12:45:12 +01:00
main.go Add -I include option, and some usage examples 2023-07-07 11:49:54 +01:00

README.md

gg

Recursive grep written in Go, for everyday ease of use.

gg is a recursive grep. Given a regexp (or fixed pattern) it will search for the pattern recursively in the current working directory. It will print a coloured header per file along with the matching line and pattern.

It is possible to scan specific files or directories, rather than the default current working directory. To do this, simply specify the path(s) as arguments following the pattern.

It is possible to scan for multiple patterns using the -e (or -Q) argument, which can be repeated multiple times. -e specifies a regular expression and -Q a fixed pattern. When using either flag, any non-flag arguments are treated as paths to scan.

Search defaults to case-sensitive but the -i flag may be passed to make all search terms case-insensitive. Alternatively, the "(?i)" construct may be added to a regular expression to make that specific expression case insensitive.

Files and directories can be excluded with the -x option. This supports bash-style globs with '*', '?', '[a-z]', '{this,that}', or '/**/' to match zero or more directories. By default, .git and vim swap files are ignored. Similarly, -I filters files to include. Examples:

	# ignore files/dirs with .js or .css suffix
	gg -x '*.js' -x '*.css' pattern

	# only match files with .go suffix (any subdir)
	gg -I '*.go' pattern

	# only match files whose parent dir is "stuff", but ignore "foo" subdir
	gg -x ./foo -I 'stuff/*' pattern

	# only match .js files with a directory "things" in the path, but ignore
	# .min.js (e.g. will match "foo/things/bar/my.js")
	gg -I 'things/**/*.js' -x '*.min.js' pattern

Symlinks named on the command line are followed, but by default symlinks are not followed when recursing into directories. -L allows them to be dereferenced.