Here's an example script I used to refactor the names of files in a C project.
It can easily be adapted to refactor variable names, etc in JavaScript, Ruby, Python, PHP (*shudder*), etc.

#!/bin/bash

if [ ! -n "${1}" ]
then
    echo "
Usage: refactor.sh new_basename old_basename

Note: do not include '.c' or '.h', this is added for you.
    "
    exit
fi

NEW=${1}
OLD=${2}

svn mv include/${OLD}.h include/${NEW}.h
svn mv ${OLD}.c ${NEW}.c


find ./ -name '*.c' | xargs sed -i "s/${OLD}\.h/${NEW}\.h/gi"
find ./ -name '*.c' | xargs sed -i "s/${OLD}\.c/${NEW}\.c/gi"

find ./ -name '*.h' | xargs sed -i "s/${OLD}\.h/${NEW}\.h/gi"
find ./ -name '*.h' | xargs sed -i "s/${OLD}\.c/${NEW}\.c/gi"

By AJ ONeal

If you loved this and want more like it, sign up!


Did I make your day?
Buy me a coffeeBuy me a coffee  

(you can learn about the bigger picture I'm working towards on my patreon page )