Skip to content

Instantly share code, notes, and snippets.

@bgrins
Created October 9, 2019 21:09
Show Gist options
  • Save bgrins/bcb3a6e72118c872b5633c8fddd9a32d to your computer and use it in GitHub Desktop.
Save bgrins/bcb3a6e72118c872b5633c8fddd9a32d to your computer and use it in GitHub Desktop.
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
@bgrins
Copy link
Author

bgrins commented Oct 9, 2019

Usage:

  • Update MOZILLA_CENTRAL to match path
  • ./find-rename-xul-files.sh xpfe (where xpfe is the directory you want to process)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment