Created
February 14, 2021 19:53
-
-
Save wallentx/5424f5b6b4c71f88bc4c65da073e825f to your computer and use it in GitHub Desktop.
Find strings across all files in given directory. Print results in a sexy manner.
This file contains hidden or 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
| #!/usr/bin/env bash | |
| set -e | |
| | |
| if ! [[ $(command -v rg) > /dev/null ]]; then | |
| echo "You need to install Ripgrep" | |
| echo "https://github.com/BurntSushi/ripgrep" | |
| exit 1 | |
| fi | |
| | |
| while getopts "t:" OPTION; do | |
| case $OPTION in | |
| t) | |
| TYPE=${OPTARG} | |
| shift "$((OPTIND-1))" | |
| ;; | |
| # f) | |
| # FILE=${OPTARG} | |
| # shift "$((OPTIND-1))" | |
| # ;; | |
| *) | |
| echo "Unknow comandline switch: $OPTION" | |
| esac | |
| done | |
| | |
| | |
| FSTRING=$1 | |
| CORES=$(python -c 'import multiprocessing as mp; print(mp.cpu_count())') | |
| | |
| findmatch() { | |
| rg --colors path:style:bold \ | |
| --colors line:style:bold \ | |
| --hidden \ | |
| --no-messages \ | |
| -M 200 \ | |
| --max-columns-preview \ | |
| -j "$CORES" \ | |
| -p "$FSTRING" \ | |
| --ignore-file "$HOME"/.ignore | \ | |
| sed 's/.*:/── Line &/' | \ | |
| sed 's/:/: \n /1' | |
| } | |
| | |
| findmatchtype() { | |
| rg --colors path:style:bold \ | |
| --colors line:style:bold \ | |
| --hidden \ | |
| --no-messages \ | |
| -M 200 \ | |
| --max-columns-preview \ | |
| -j "$CORES" \ | |
| -p "$FSTRING" \ | |
| --type "$TYPE" \ | |
| --ignore-file "$HOME"/.ignore | \ | |
| sed 's/.*:/── Line &/' | \ | |
| sed 's/:/: \n /1' | |
| } | |
| | |
| findmatchfile() { | |
| rg --colors path:style:bold \ | |
| --colors line:style:bold \ | |
| --hidden \ | |
| --no-messages \ | |
| -M 200 \ | |
| --max-columns-preview \ | |
| -j "$CORES" \ | |
| -p "$FSTRING" {./"$FILE",*/"$FILE",*/*/"$FILE",*/*/*/"$FILE",*/*/*/*/"$FILE",*/*/*/*/*/"$FILE",*/*/*/*/*/*/"$FILE",*/*/*/*/*/*/*/"$FILE"} \ | |
| --ignore-file "$HOME"/.ignore | \ | |
| sed 's/.*:/── Line &/' | \ | |
| sed 's/:/: \n /1' | |
| } | |
| | |
| if [[ -n ${TYPE} ]]; then | |
| findmatchtype | |
| elif [[ -n ${FILE} ]]; then | |
| findmatchfile | |
| else | |
| findmatch | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment