Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefsCleaner.sh (for Linux/Mac) #405

Merged
merged 11 commits into from Apr 24, 2018
27 changes: 14 additions & 13 deletions prefsCleaner.sh
Expand Up @@ -2,11 +2,10 @@

## prefs.js cleaner for Linux/Mac
## author: @claustromaniac
## version: 1.0b5
## version: 1.0b6

## special thanks to @overdodactyl and @earthlng for a few snippets that I stol..*cough* borrowed from the updater.sh

set -eu
currdir=$(pwd)

## get the full path of this script (readlink for Linux, greadlink for Mac with coreutils installed)
Expand All @@ -21,6 +20,7 @@ cd "$(dirname "${sfp}")"
fQuit() {
## change directory back to the original working directory
cd "${currdir}"
echo -e "\n$2"
exit $1
}

Expand All @@ -38,15 +38,15 @@ fClean() {
prefs="@@"
prefexp="user_pref[ ]*\([ ]*[\"']([^\"']*)[\"'][ ]*,"
while read -r line || [[ -n "$line" ]]; do
if [[ $line =~ $prefexp ]]; then
if [[ "$line" =~ $prefexp ]]; then
if [[ $prefs != *"@@${BASH_REMATCH[1]}@@"* ]]; then
prefs="${prefs}${BASH_REMATCH[1]}@@"
fi
fi
done <<< `grep -E "${prefexp}" user.js`
done <<< $(grep -E "${prefexp}" user.js)

while IFS='' read -r line || [[ -n "$line" ]]; do
if [[ $line =~ $prefexp ]]; then
if [[ "$line" =~ ^$prefexp ]]; then
if [[ $prefs != *"@@${BASH_REMATCH[1]}@@"* ]]; then
echo "$line"
fi
Expand All @@ -60,7 +60,7 @@ echo -e "\n\n"
echo " ╔══════════════════════════╗"
echo " ║ prefs.js cleaner ║"
echo " ║ by claustromaniac ║"
echo " ║ v1.0b5 ║"
echo " ║ v1.0b6 ║"
echo " ╚══════════════════════════╝"
echo -e "\nThis script should be run from your Firefox profile directory.\n"
echo "It will remove any entries from prefs.js that also exist in user.js."
Expand All @@ -70,22 +70,23 @@ select option in Start Help Exit; do
case $option in
Start)
if [ ! -e user.js ]; then
echo "user.js not found in the current directory."
fQuit 1
fQuit 1 "user.js not found in the current directory."
elif [ ! -e prefs.js ]; then
echo "prefs.js not found in the current directory."
fQuit 1
fQuit 1 "prefs.js not found in the current directory."
fi

fFF_check
## create backup folder if it doesn't exist
mkdir -p userjs_backups;
bakfile="userjs_backups/prefs.js.backup.$(date +"%Y-%m-%d_%H%M")"
mv prefs.js "${bakfile}" && echo -e "\nprefs.js backed up: $bakfile"
mv prefs.js "${bakfile}"
if [ ! $? ]; then
fQuit 1 "Operation aborted.\nReason: Could not create backup file $bakfile"
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mv prefs.js "${bakfile}" || fQuit 1 "Operation aborted.\nReason: Could not create backup file $bakfile"

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I originally wrote it the other way around (if it doesn't fail do stuff). The if clause was a remnant of it. Didn't think it through.

echo -e "\nprefs.js backed up: $bakfile"
echo "Cleaning prefs.js..."
fClean "$bakfile"
echo "All done!"
fQuit 0
fQuit 0 "All done!"
;;
Help)
echo -e "\nThis script creates a backup of your prefs.js file before doing anything."
Expand Down