Created
May 18, 2022 17:37
-
-
Save gabrielfalcao/5c700d2bbd1c0b11788ee9a06bb20b6c to your computer and use it in GitHub Desktop.
A very simple CLI script for code refactoring. Basically combines ack + gnu-sed
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
#!/bin/bash | |
original="$1" | |
replacement="$2" | |
echo "Replacing $original with $replacement" | |
ack -l $original * | cut -d: -f1 | uniq | xargs gsed -i "s,$original,$replacement,g" | |
if [ -z $3 ]; then | |
original=`echo $original | tr '[:lower:]' '[:upper:]'` | |
replacement=`echo $replacement | tr '[:lower:]' '[:upper:]'` | |
echo "Replacing $original with $replacement" | |
ack -l $original * | cut -d: -f1 | uniq | xargs gsed -i "s,$original,$replacement,g" | |
original=`echo $original | tr '[:upper:]' '[:lower:]'` | |
replacement=`echo $replacement | tr '[:upper:]' '[:lower:]'` | |
echo "Replacing $original with $replacement" | |
ack -l $original * | cut -d: -f1 | uniq | xargs gsed -i "s,$original,$replacement,g" | |
fi; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment