Last active
December 2, 2021 20:17
-
-
Save peregrinogris/1256258 to your computer and use it in GitHub Desktop.
Custom flavored grep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
EXCLUDEDIR=${EXCLUDEDIR:-"env/*"} | |
COLOR=${COLOR:-always} | |
CONTEXT=${CONTEXT:-0} | |
grep -IiRn --exclude="$EXCLUDE" --exclude-dir="$EXCLUDEDIR" --color=$COLOR -C$CONTEXT "$1" * \ | |
| less -iFRX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ "$EXCLUDE" != "" ]]; then | |
EXCLUDE="!$EXCLUDE" | |
fi | |
COLOR=${COLOR:-always} | |
CONTEXT=${CONTEXT:-0} | |
rg -in -g "$EXCLUDE" --color=$COLOR -C$CONTEXT "$1" \ | |
| less -iFRX |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Custom Flavored Grep
Some time ago I realized that I used grep too often with an irksome set of flags, so I made this bash script to set them for me. I mainly use
grepc
to browse through the mozilla-central source code, to find function definitions, calls, etc.I know you can probably do this from within vim or emacs, but sometimes you're wandering around in the terminal and this just does the trick
Installation
I generally save this file as
/usr/local/bin/grepc
, setting it as executable.Usage
Run:
And the output will be a list of the files with that string, showing the matched line with the string highlighted and line-number.
Options:
Use the variable
COLOR
to override the default color output (--color=always):Use the variable
EXCLUDEDIR
to override the default excluded folder (env/*
):Use the variable
EXCLUDE
to exclude files from the results:Use the variable
CONTEXT
to add that many context lines before and after the match:Changelog