-
-
Save albfan/63761ddae10f301afcc1f52b3d132c36 to your computer and use it in GitHub Desktop.
https://github.com/lydell/dotfiles/blob/330e9245ba8f820e2459a876d31cad78a49215b3/bin/pre polished
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
#!/usr/bin/env bash | |
seenReplace='' | |
for arg in "$@"; do | |
if test "$arg" == '--replace'; then | |
seenReplace='true' | |
break | |
fi | |
done | |
if test -z "$seenReplace"; then | |
echo 'You must specify the --replace argument!' | |
exit 1 | |
fi | |
currentFile='' | |
didChange='' | |
( | |
rg \ | |
--context 999999 \ | |
--with-filename --heading --null \ | |
--color=never --no-line-number \ | |
"$@" | |
echo -e '\n\0' | |
) | | |
{ | |
while IFS= read -r -d '' part; do | |
if test -n "$currentFile"; then | |
echo "$currentFile" | |
head -n -2 <<< "$part" > "$currentFile" | |
didChange='true' | |
fi | |
currentFile="$(tail -n 1 <<< "$part")" | |
done | |
if test -z "$didChange"; then | |
echo "No files were changed." | |
exit 1 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment