Created
October 9, 2019 21:09
-
-
Save bgrins/bcb3a6e72118c872b5633c8fddd9a32d to your computer and use it in GitHub Desktop.
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
MOZILLA_CENTRAL=~/Code/mozilla-central | |
if [ ! -f $MOZILLA_CENTRAL/test.mozbuild ]; then | |
echo "Error: this doesn't look like an m-c directory." | |
exit 1 | |
fi | |
# Generate a list of directories to ignore using the built in list | |
# plus files ignored by VCS, plus other whitelisted ones here. | |
THIRD_PARTY_LIST="$(sed 's/^/\//' $MOZILLA_CENTRAL/tools/rewriting/ThirdPartyPaths.txt)" | |
GIT_IGNORE_LIST="$(sed '/^#/d;/^$/d' $MOZILLA_CENTRAL/.gitignore)" | |
IGNORE_LIST="${THIRD_PARTY_LIST} | |
${GIT_IGNORE_LIST}" | |
IGNORE_LIST="${IGNORE_LIST}" | |
#**test**" | |
IGNORE_ARGS="" | |
while read -r line; do | |
IGNORE_ARGS="$IGNORE_ARGS --iglob '!$line'" | |
done <<< "$IGNORE_LIST" | |
function get_matching_files_for_dir() { | |
eval "rg -l -g '*.{xul}' $IGNORE_ARGS \"\" $1 | sort" | |
} | |
matching_files=$(get_matching_files_for_dir $1) | |
echo "$matching_files" > xulfiles.txt | |
function get_matching_files_for_dir() { | |
eval "rg --files-with-matches '$1' $2" | |
} | |
while read oldpath; do | |
olddir=`dirname $oldpath` | |
oldname=`basename $oldpath` | |
newname="${oldname/\.xul/.xhtml}" | |
newpath="${oldpath/\.xul/.xhtml}" | |
echo "Renaming $oldpath -> $newpath" | |
hg mv $oldpath $newpath | |
echo "Replacing text matches of $oldname with $newname" | |
matchingfiles=$(get_matching_files_for_dir $oldname $olddir) | |
eval "perl -pi -e 's/$oldname/$newname/g;' $matchingfiles" | |
done < xulfiles.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
./find-rename-xul-files.sh xpfe
(where xpfe is the directory you want to process)