A fast, interactive search and replace tool for your terminal, powered by Bubble Tea and Lipgloss.
- 🚀 Fast regex search across files and directories
- 🖥️ Interactive TUI for previewing and selecting replacements
- 🧠 Smart selection: choose lines to replace, bulk select/deselect
- 🛡️ Atomic file writes for safe replacements
- 🎨 Customizable styles and clear error messages
- 🏃 Efficient for large codebases
go install github.com/albertize/gref@latestGo to github.com/albertize/gref/releases and download the package for your platform (Linux, macOS, Windows) from the "Assets" section.
You can also build binaries locally:
make build-allYou will find the binaries in the dist/ folder for Linux, macOS, and Windows.
For a quick local build and install:
make build-localThe binary will be copied to $HOME/go/bin.
gref [options] <pattern> [replacement] [directory]-h,--help: Show help message and exit-i,--ignore-case: Ignore case in pattern matching-e,--exclude: Exclude path, file or extension (comma separated, e.g..git,*.log,media/)
<pattern>: Regex pattern to search for[replacement]: Replacement string (if omitted, only search)[directory]: Directory to search (default: current directory)
gref foo bar src # Replace 'foo' with 'bar' in src directory
gref foo # Search for 'foo' only
gref -i Foo # Case-insensitive search for 'Foo'
gref --help # Show help message
gref -e .git,*.log # Exclude .git folders and .log files-h,--help: Show help message and exit-i,--ignore-case: Ignore case in pattern matching
<pattern>: Regex pattern to search for[replacement]: Replacement string (if omitted, only search)[directory]: Directory to search (default: current directory)
gref foo bar src # Replace 'foo' with 'bar' in src directory
gref foo # Search for 'foo' only
gref -i Foo # Case-insensitive search for 'Foo'
gref --help # Show help message↑/↓/j/k: Move cursor up/down←/→/h/l: Scroll horizontallyHome/End: Scroll to start/end of lineSpace: Select/deselect a result for replacementa: Select all resultsn: Deselect all resultsEnter: Confirm selected replacementsEsc: Cancel confirmationq/Ctrl+c: Exit
- main.go: CLI entry, argument parsing, help, and UI launch
- model.go: TUI state, rendering, and event handling
- search.go: Efficient regex search across files, exclusion logic
- replace.go: Safe, grouped replacements in files
- test/replace_test.go: Extensive edge case tests for replace (Windows/Unix line endings, empty files, binary/null bytes, permission errors, overlapping matches, invalid regex, etc.)
- test/search_test.go: Tests for exclude logic and pattern parsing
GREF is designed for speed and efficiency:
- Optimized Search: Buffered reading and byte-level processing for large files
- Parallel File Traversal: Uses Go concurrency for fast directory scanning
- Atomic Replacements: Writes changes to temp files before replacing originals
- Minimal UI Overhead: Responsive TUI adapts to terminal size
- Selective Processing: Only selected lines/files are modified
- Bubble Tea: TUI framework
- Lipgloss: Terminal style toolkit
Contributions are welcome! Please submit issues or pull requests for bug fixes, features, or improvements.
MIT License
