Skip to content

Instantly share code, notes, and snippets.

@stansidel
Created December 15, 2023 13:10
Show Gist options
  • Save stansidel/4cec35876f56067ebff0fe44bc60d192 to your computer and use it in GitHub Desktop.
Save stansidel/4cec35876f56067ebff0fe44bc60d192 to your computer and use it in GitHub Desktop.
Update all files for GPB Sandbox
#!/bin/bash
OLD_NAME="NDBOFeatureToggles"
NEW_NAME=$1
if [ -z "$NEW_NAME" ]; then
echo "Usage: $0 <new name>"
exit 1
fi
# Rename all files and directories that contain the old name to the new name.
# First, print out all the changes that will be made including the initial and final names of the files and directories that will be renamed. Then, rename all files and directories that contain the old name to the new name. Finally, print out all the files and directories that still contain the old name to check that none remain
echo "The following files and directories will be renamed:"
LC_ALL=C find . -name "*$OLD_NAME*" -print0 | while read -d $'\0' f; do echo "$f -> ${f//$OLD_NAME/$NEW_NAME}"; done
# Then ask the user if we should continue and perform the actual renaming
# read -p "Continue? [y/n] " -n 1 -r
LC_ALL=C find . -name "*$OLD_NAME*" -print0 | while read -d $'\0' f; do mv "$f" "${f//$OLD_NAME/$NEW_NAME}"; done
# Printing out all files that will be changed
echo "The following files will be changed:"
LC_ALL=C find . -type f -exec grep -l "$OLD_NAME" {} \;
# read -p "Continue? [y/n] " -n 1 -r
# Replacing all occurrences of the old name with the new name
LC_ALL=C find . -type f -exec sed -i "" "s/$OLD_NAME/$NEW_NAME/g" {} \;
# Printing out all files with the old name to check none remain
echo "The following files still have the old name:"
LC_ALL=C find . -type f -exec grep -l "$OLD_NAME" {} \;
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment