Last active
November 29, 2022 17:05
-
-
Save Integralist/89ad7fe05f72941b87c6e3512c30d940 to your computer and use it in GitHub Desktop.
[RipGrep inline file replacements] #riggrep #rg #sed #replacement #bash #shell
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 | |
# DESCRIPTION: | |
# Replaces all instances where... | |
# | |
# `Id` should be `ID` | |
# `Acl` should be `ACL` | |
# `Http` should be `HTTP` | |
# | |
# DEPENDENCIES: | |
# brew install ripgrep | |
CLIENT=$1 | |
function replace { | |
local pattern=$1 | |
local replacement=$2 | |
local file=$3 | |
rg $1 \ | |
--case-sensitive \ | |
--type go \ | |
--type md \ | |
--color never \ | |
--no-line-number \ | |
--passthru \ | |
--replace $2 \ | |
"$file" > tmp.txt && mv tmp.txt "$file" | |
rm tmp.txt 2> /dev/null | |
} | |
FILES="./$CLIENT/**/*" | |
for f in $FILES | |
do | |
echo "Processing $f..." | |
# ID | |
replace '\b(\w+)Id([A-Z]\w+)?\b' '${1}ID${2}' "$f" | |
# ACL | |
replace '([a-z])?Acl(\w+)?\b' '${1}ACL${2}' "$f" | |
# HTTP | |
replace '([a-z])?Http(\w+)?\b' '${1}HTTP${2}' "$f" | |
done | |
cd ./tests/simple-client-test/go-client-test | |
go run main.go | |
cd - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment