Skip to content

Commit

Permalink
Moving engine to gf JSON files as an optional entry
Browse files Browse the repository at this point in the history
  • Loading branch information
omerxx committed Apr 30, 2020
1 parent 4d03d69 commit a428d41
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,18 @@ alias the gf binary to something else, or `unalias gf` to remove the `git fetch`
There are some amazing code searching engines out there that can be a better replacement for grep.
A good example is [the silver searcher](https://github.com/ggreer/the_silver_searcher).
It's faster (like **way faster**) and presents the results in a more visually digestible manner.
In order to utilize a different engine, use `-engine` and provide a different tool like so:
In order to utilize a different engine, add `engine: <other tool>` to the relevant pattern file:
```bash
# Using the silver searcher instead of grep
gf -engine ag api-keys
# Using the silver searcher instead of grep for the aws-keys pattern:
# 1. Adding "ag" engine
# 2. Removing the E flag which is irrelevant for ag
{
"engine": "ag",
"flags": "-Hanr",
"pattern": "([^A-Z0-9]|^)(AKIA|A3T|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{12,}"
}
```
* Note I: Different engines use different flags, so in the example above, the flag `E` has to be removed from the `api-keys.json` file in order of ag to successfully run.
* Note II: You'd probably want to `alias <command>='gf -engine <engine>'` if you plan to use this regularly.
* Note: Different engines use different flags, so in the example above, the flag `E` has to be removed from the `aws-keys.json` file in order for ag to successfully run.


## Install
Expand Down
8 changes: 3 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type pattern struct {
Flags string `json:"flags,omitempty"`
Pattern string `json:"pattern,omitempty"`
Patterns []string `json:"patterns,omitempty"`
Engine string `json:"engine,omitempty"`
}

func main() {
Expand All @@ -28,9 +29,6 @@ func main() {
var dumpMode bool
flag.BoolVar(&dumpMode, "dump", false, "prints the grep command rather than executing it")

var engine string
flag.StringVar(&engine, "engine", "grep", "uses a different engine instead of grep e.g. ag")

flag.Parse()

if listMode {
Expand Down Expand Up @@ -102,8 +100,8 @@ func main() {
} else {
var cmd *exec.Cmd
operator := "grep"
if engine != "" {
operator = engine
if pat.Engine != "" {
operator = pat.Engine
}

if stdinIsPipe() {
Expand Down

0 comments on commit a428d41

Please sign in to comment.