22
33# # prefs.js cleaner for Linux/Mac
44# # author: @claustromaniac
5- # # version: 1.3
5+ # # version: 1.4
66
77# # special thanks to @overdodactyl and @earthlng for a few snippets that I stol..*cough* borrowed from the updater.sh
88
@@ -20,15 +20,22 @@ cd "$(dirname "${sfp}")"
2020fQuit () {
2121 # # change directory back to the original working directory
2222 cd " ${currdir} "
23- echo -e " \n$2 "
23+ [ $1 -eq 0 ] && echo -e " \n$2 " || echo -e " \n $2 " >&2
2424 exit $1
2525}
2626
27+ fUsage () {
28+ echo -e " \nUsage: $0 [-s]"
29+ echo -e "
30+ Optional Arguments:
31+ -s Start immediately"
32+ }
33+
2734fFF_check () {
2835 # there are many ways to see if firefox is running or not, some more reliable than others
2936 # this isn't elegant and might not be future-proof but should at least be compatible with any environment
3037 while [ -e lock ]; do
31- echo -e " \nThis Firefox profile seems to be in use. Close Firefox and try again.\n"
38+ echo -e " \nThis Firefox profile seems to be in use. Close Firefox and try again.\n" >&2
3239 read -p " Press any key to continue."
3340 done
3441}
@@ -54,34 +61,42 @@ fClean() {
5461 done < " $1 " > prefs.js
5562}
5663
64+ fStart() {
65+ if [ ! -e user.js ]; then
66+ fQuit 1 " user.js not found in the current directory."
67+ elif [ ! -e prefs.js ]; then
68+ fQuit 1 " prefs.js not found in the current directory."
69+ fi
70+
71+ fFF_check
72+ bakfile=" prefs.js.backup.$( date +" %Y-%m-%d_%H%M" ) "
73+ mv prefs.js " ${bakfile} " || fQuit 1 " Operation aborted.\n Reason: Could not create backup file $bakfile "
74+ echo -e " \n prefs.js backed up: $bakfile "
75+ echo " Cleaning prefs.js..."
76+ fClean " $bakfile "
77+ fQuit 0 " All done! "
78+ }
79+
5780echo -e " \n\n "
5881echo " ╔══════════════════════════╗"
5982echo " ║ prefs.js cleaner ║"
6083echo " ║ by claustromaniac ║"
61- echo " ║ v1.3 ║"
84+ echo " ║ v1.4 ║"
6285echo " ╚══════════════════════════╝"
6386echo -e " \n This script should be run from your Firefox profile directory.\n "
6487echo " It will remove any entries from prefs.js that also exist in user.js."
6588echo " This will allow inactive preferences to be reset to their default values."
6689echo -e " \n This Firefox profile shouldn' t be in use during the process.\n"
90+
91+ [ "$1" == ' -s' ] && fStart
92+
6793select option in Start Help Exit; do
6894 case $option in
6995 Start)
70- if [ ! -e user.js ]; then
71- fQuit 1 "user.js not found in the current directory."
72- elif [ ! -e prefs.js ]; then
73- fQuit 1 "prefs.js not found in the current directory."
74- fi
75-
76- fFF_check
77- bakfile="prefs.js.backup.$(date +"%Y-%m-%d_%H%M")"
78- mv prefs.js "${bakfile}" || fQuit 1 "Operation aborted.\nReason: Could not create backup file $bakfile"
79- echo -e "\nprefs.js backed up: $bakfile"
80- echo "Cleaning prefs.js..."
81- fClean "$bakfile"
82- fQuit 0 "All done!"
96+ fStart
8397 ;;
8498 Help)
99+ fUsage
85100 echo -e "\nThis script creates a backup of your prefs.js file before doing anything."
86101 echo -e "It should be safe, but you can follow these steps if something goes wrong:\n"
87102 echo "1. Make sure Firefox is closed."
0 commit comments