Skip to content

Instantly share code, notes, and snippets.

@Integralist
Last active November 29, 2022 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Integralist/89ad7fe05f72941b87c6e3512c30d940 to your computer and use it in GitHub Desktop.
Save Integralist/89ad7fe05f72941b87c6e3512c30d940 to your computer and use it in GitHub Desktop.
[RipGrep inline file replacements] #riggrep #rg #sed #replacement #bash #shell
#!/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