gf
is a powerful command-line tool written in Rust for managing and using reusable search patterns with grep-like tools. It allows you to save, list, and execute complex search patterns easily, improving your productivity in tasks like code analysis, security auditing, and text processing.
- Save Search Patterns: Save complex grep patterns with custom flags and reuse them anytime.
- Pattern Listing: List all saved patterns for easy reference.
- Customizable Engines: Use different search engines like
grep
,rg
(ripgrep), orag
(The Silver Searcher). - Pattern Execution: Execute saved patterns directly on files or piped input.
- Command Dumping: Print the full command that would be executed without running it.
Download the latest release for your platform from the Releases page and place the binary in your $PATH
.
To build gf
from source, ensure you have Rust and Cargo installed.
# Clone the repository
git clone https://github.com/Periecle/gf.git
cd gf
# Build the project and install it to PATH
cargo install --path .
gf --save <pattern-name> [--engine <engine>] [flags] <search-pattern>
gf <pattern-name> [file or directory]
gf --list
gf --dump <pattern-name> [file or directory]
Usage: gf [OPTIONS] [NAME] [ARGS]...
Pattern manager for grep-like tools
Options:
--save Save a pattern (e.g., gf --save pat-name -Hnri 'search-pattern')
--list List available patterns
--dump Print the command rather than executing it
--engine <ENGINE> Specify the engine to use (e.g., 'grep', 'rg', 'ag')
-h, --help Print help information
-V, --version Print version information
Arguments:
[NAME] The name of the pattern (when saving or using)
[ARGS]... Additional arguments
Save a pattern named find-todos to search for TODO comments:
gf --save find-todos -nri "TODO"
Use the saved pattern to search in the current directory:
gf find-todos
Save a pattern using rg (ripgrep) as the search engine:
gf --save find-errors --engine rg -nri "ERROR"
Use the saved pattern:
gf find-errors /var/log
List all saved patterns:
gf --list
Dump the command that would be executed for a pattern:
gf --dump find-todos src/
Output:
grep -nri "TODO" src/
Use a pattern with piped input:
cat file.txt | gf find-todos
Save a pattern without any flags:
gf --save simple-search "" "pattern-to-search"
Attempting to use a non-existent pattern:
gf nonexistent-pattern
Output:
Error: No such pattern 'nonexistent-pattern'
This tool was originally written by tomnomnom in Go.
Contributions are welcome! Please follow these steps:
Fork the repository. Create a new branch with your feature or bug fix. Commit your changes with clear and descriptive messages. Push to your branch. Open a pull request on GitHub. Please ensure that your code adheres to the existing style and passes all tests.
This project is licensed under the MIT License. See the LICENSE file for details.