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
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
548f0f7
v1.0b
claustromaniac 3c093e6
v1.0b2
claustromaniac cada20a
v1.0b3
claustromaniac c469249
Update prefsCleaner.sh
claustromaniac 7ef1e49
v1.0b4
claustromaniac 3090b6f
v1.0b5
claustromaniac 22a8ebe
I'm actually more of a tabs guy
claustromaniac 46123f4
v1.0b6
claustromaniac 89e603d
v1.0b7
claustromaniac 7f09546
Update prefsCleaner.sh
claustromaniac f1ad9f6
Update prefsCleaner.sh
earthlng File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#!/usr/bin/env bash | ||
|
||
## prefs.js cleaner for Linux/Mac | ||
## author: @claustromaniac | ||
## version: 1.0b6 | ||
|
||
## special thanks to @overdodactyl and @earthlng for a few snippets that I stol..*cough* borrowed from the updater.sh | ||
|
||
currdir=$(pwd) | ||
|
||
## get the full path of this script (readlink for Linux, greadlink for Mac with coreutils installed) | ||
sfp=$(readlink -f "${BASH_SOURCE[0]}" 2>/dev/null || greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null) | ||
|
||
## fallback for Macs without coreutils | ||
if [ -z "$sfp" ]; then sfp=${BASH_SOURCE[0]}; fi | ||
|
||
## change directory to the Firefox profile directory | ||
cd "$(dirname "${sfp}")" | ||
|
||
fQuit() { | ||
## change directory back to the original working directory | ||
cd "${currdir}" | ||
echo -e "\n$2" | ||
exit $1 | ||
} | ||
|
||
fFF_check() { | ||
# there are many ways to see if firefox is running or not, some more reliable than others | ||
# this isn't elegant and might not be future-proof but should at least be compatible with any environment | ||
while [ -e webappsstore.sqlite-shm ]; do | ||
echo -e "\nThis Firefox profile seems to be in use. Close Firefox and try again.\n" | ||
read -p "Press any key to continue." | ||
done | ||
} | ||
|
||
fClean() { | ||
# the magic happens here | ||
prefs="@@" | ||
prefexp="user_pref[ ]*\([ ]*[\"']([^\"']*)[\"'][ ]*," | ||
while read -r line || [[ -n "$line" ]]; do | ||
if [[ "$line" =~ $prefexp ]]; then | ||
if [[ $prefs != *"@@${BASH_REMATCH[1]}@@"* ]]; then | ||
prefs="${prefs}${BASH_REMATCH[1]}@@" | ||
fi | ||
fi | ||
done <<< $(grep -E "${prefexp}" user.js) | ||
|
||
while IFS='' read -r line || [[ -n "$line" ]]; do | ||
if [[ "$line" =~ ^$prefexp ]]; then | ||
if [[ $prefs != *"@@${BASH_REMATCH[1]}@@"* ]]; then | ||
echo "$line" | ||
fi | ||
continue | ||
fi | ||
echo "$line" | ||
done < "$1" > prefs.js | ||
} | ||
|
||
echo -e "\n\n" | ||
echo " ╔══════════════════════════╗" | ||
echo " ║ prefs.js cleaner ║" | ||
echo " ║ by claustromaniac ║" | ||
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." | ||
echo "This will allow inactive preferences to be reset to their default values." | ||
echo -e "\nThis Firefox profile shouldn't be in use during the process.\n" | ||
select option in Start Help Exit; do | ||
case $option in | ||
Start) | ||
if [ ! -e user.js ]; then | ||
fQuit 1 "user.js not found in the current directory." | ||
elif [ ! -e prefs.js ]; then | ||
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}" | ||
if [ ! $? ]; then | ||
fQuit 1 "Operation aborted.\nReason: Could not create backup file $bakfile" | ||
fi | ||
echo -e "\nprefs.js backed up: $bakfile" | ||
echo "Cleaning prefs.js..." | ||
fClean "$bakfile" | ||
fQuit 0 "All done!" | ||
;; | ||
Help) | ||
echo -e "\nThis script creates a backup of your prefs.js file before doing anything." | ||
echo -e "It should be safe, but you can follow these steps if something goes wrong:\n" | ||
echo "1. Make sure Firefox is closed." | ||
echo "2. Delete prefs.js in your profile folder." | ||
echo "3. Delete Invalidprefs.js if you have one in the same folder." | ||
echo "4. Rename or copy your latest backup to prefs.js." | ||
echo "5. Run Firefox and see if you notice anything wrong with it." | ||
echo "6. If you do notice something wrong, especially with your extensions, and/or with the UI, go to about:support, and restart Firefox with add-ons disabled. Then, restart it again normally, and see if the problems were solved." | ||
echo -e "If you are able to identify the cause of your issues, please bring it up on ghacks-user.js GitHub repository.\n" | ||
;; | ||
Exit) | ||
fQuit 0 | ||
;; | ||
esac | ||
done |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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"
?
There was a problem hiding this comment.
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.