Skip to content

Instantly share code, notes, and snippets.

@benlumley
Created November 6, 2011 09:03
Show Gist options
  • Save benlumley/1342665 to your computer and use it in GitHub Desktop.
Save benlumley/1342665 to your computer and use it in GitHub Desktop.
Shell script to help moving/renaming a symfony module - replaces in files and renames files
#!/bin/bash
#
# Aims to rename a symfony1 module, including renaming files and directories and replacing all usages within files
#
# Usage
#
# CD to module folder (ie: modules/old_module) and run. Then rename the module dir itself.
#
# If you are brave, may also work in modules folder and will then rename module dir too.
# But will replace in all modules - which may be a problem.
#
# run ./thisscript.sh OldModel old_module NewModel new_module
#
oldname=$1
old_underscored=$2
newname=$3
new_underscored=$4
echo "In files, $oldname => $newname";
find ./ -type f -exec sed -i "s/$oldname/$newname/" {} \;
echo "In files, $old_underscored => $new_underscored";
find ./ -type f -exec sed -i "s/$old_underscored/$new_underscored/" {} \;
echo "Filenames, $oldname => $newname";
for filename in `find -name "*$oldname*"`; do
echo "Renaming $filename";
newfilename=`echo $filename | sed -e "s/$oldname/$newname/g"`;
echo "$filename > $newfilename";
mv $filename $newfilename;
done;
echo "Filenames, $old_underscored => $new_underscored";
for filename in `find -name "*$old_underscored*"`; do
echo "Renaming $filename";
newfilename=`echo $filename | sed -e "s/$old_underscored/$new_underscored/g"`;
echo "$filename > $newfilename";
mv $filename $newfilename;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment