Skip to content

Commit 9018577

Browse files
authored
v1.4 (#1189)
- add -s parameter to start immediately / skip prompt / run non-interactive This is useful if the user wants to automate the process of updating the user.js and cleaning prefs. - fQuit: error messages to stderr - fFF_check: info msg to stderr Better support for suppressing/redirecting stdout while still showing any error messages in the console, useful for example with `prefsCleaner.sh -s >/dev/null`
1 parent 6968b9a commit 9018577

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

prefsCleaner.sh

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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}")"
2020
fQuit() {
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+
2734
fFF_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.\nReason: Could not create backup file $bakfile"
74+
echo -e "\nprefs.js backed up: $bakfile"
75+
echo "Cleaning prefs.js..."
76+
fClean "$bakfile"
77+
fQuit 0 "All done!"
78+
}
79+
5780
echo -e "\n\n"
5881
echo " ╔══════════════════════════╗"
5982
echo " ║ prefs.js cleaner ║"
6083
echo " ║ by claustromaniac ║"
61-
echo " ║ v1.3"
84+
echo " ║ v1.4"
6285
echo " ╚══════════════════════════╝"
6386
echo -e "\nThis script should be run from your Firefox profile directory.\n"
6487
echo "It will remove any entries from prefs.js that also exist in user.js."
6588
echo "This will allow inactive preferences to be reset to their default values."
6689
echo -e "\nThis Firefox profile shouldn't be in use during the process.\n"
90+
91+
[ "$1" == '-s' ] && fStart
92+
6793
select 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

Comments
 (0)