https://github.com/andrewrosss/filter-hunks
Bash script to filter hunks in a unified diff
https://github.com/andrewrosss/filter-hunks
Last synced: about 1 month ago
JSON representation
Bash script to filter hunks in a unified diff
- Host: GitHub
- URL: https://github.com/andrewrosss/filter-hunks
- Owner: andrewrosss
- License: mit
- Created: 2024-10-10T03:34:17.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-04-01T02:29:53.000Z (about 1 month ago)
- Last Synced: 2025-04-05T14:35:24.760Z (about 1 month ago)
- Language: Shell
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# filter-hunks
A simple bash script to filter hunks from a unified diff using regular expressions (regexes).
There are lots of existing tools which do this, but sometimes it's easier to copy/paste a script and be on your way.
## Usage
`filter_hunks.sh` reads from STDIN and writes to STDOUT.
```bash
Usage: src/filter_hunks.sh [options]
Options:
-I, --include Include only file paths matching this regex pattern
-X, --exclude Exclude file paths matching this regex pattern
```Example:
```bash
# keep only hunks that contain the word 'foo'
cat my.diff | filter_hunks.sh '.*foo.*'
# ^^^^^^^^^
# └- keep only hunks that contain 'foo'# keep only hunks that modify files in the 'src/'
cat my.diff | filter_hunks.sh -I 'src\/' '.*'
# ^^^^^^^ ^^^^
# | └- keep all hunks
# |
# include only files with 'src/' in the path# keep only hunks that do not modify files ending in '_test.py'
cat my.diff | filter_hunks.sh -X '.*_test\.py$' '.*'
# ^^^^^^^^^^^^^^ ^^^^
# | └- keep all hunks
# |
# exclude files ending in '_test.py'
```