bat-extras: batgrep

February 12, 2024 ยท View on GitHub

Quickly search through and highlight files using ripgrep.

Search through files or directories looking for matching regular expressions (or fixed strings with -F), and print the output using bat for an easy and syntax-highlighted experience.

Usage

batgrep [OPTIONS] PATTERN [PATH...]

Options

ShortLongDescription
-i--ignore-caseUse case insensitive searching.
-s--case-sensitiveUse case sensitive searching.
-S--smart-caseUse smart case searching.
-A--after-context=[LINES]Display the next n lines after a matched line.
-B--before-context=[LINES]Display the previous n lines before a matched line.
-C--context=[LINES]A combination of --after-context and --before-context.
-p--search-patternTell pager to search for PATTERN. Currently supported pagers: less.
--no-followDo not follow symlinks.
--no-snipDo not show the snip decoration.

This is automatically enabled when --context=0 or when bat --version is less than 0.12.x.
--no-highlightDo not highlight matching lines.

This is automatically enabled when --context=0.
--colorForce color output.
--no-colorForce disable color output.
--paging=["never"/"always"]Enable/disable paging.
--pager=[PAGER]Specify the pager to use.
--terminal-width=[COLS]Generate output for the specified terminal width.
--no-separatorDisable printing separator between files.
--rgaUse ripgrep-all instead of ripgrep.

The following options are passed directly to ripgrep, and are not handled by this script.

ShortLongNotes
-F--fixed-strings
-U--multiline
-P--pcre2
-z--search-zip
-w--word-regexp
--one-file-system
--multiline-dotall
--ignore / --no-ignore
--crlf / --no-crlf
--hidden / --no-hidden
-E--encodingThis is unsupported by bat, and may cause issues when trying to display unsupported encodings.
-g--glob
-t--type
-T--type-not
-m--max-count
--max-depth
--iglob
--ignore-file

Installation

This script is a part of the bat-extras suite of scripts. You can find install instructions here.

Caveats

Differences from ripgrep:

  • --follow is enabled by default for batgrep.

  • Not all the ripgrep options are supported.

Issues?

If you find an issue or have a feature suggestion, make a pull request or issue through GitHub! Contributions are always welcome.