How to show list of installed extensions for firefox via command line?
Solution 1:
Give a try to this grep
oneliner command to list all the firefox addons,
grep -oP '(?<=\},\"name\":\")([^"]*)' ~/.mozilla/firefox/*.default/addons.json
OR
This worked for me:
user@host:~$ cat ~/.mozilla/firefox/*.default/addons.json |
python -c 'import json,sys;obj=json.load(sys.stdin);
for (i, x) in enumerate(obj["addons"]):
print x["name"]' | uniq
Output in my case:
Clean Links
Tee-Timer
Explanation:
-
cat ~/.mozilla/firefox/*.default/addons.json
: reads the addons.json file in each profile. -
python -c 'import json,sys;obj=json.load(sys.stdin);
load the json parser library of python and loads json via stdin (standard input), ergo fromcat
-
for (i, x) in enumerate(obj["addons"]):
phyton code to loop through the array of addons... -
print x["name"]' | uniq
...and print its name only one.
Solution 2:
This is basically just a simplified version of @chaos's approach:
grep -oP '},"name":"\K[^"]*' ~/.mozilla/firefox/*.default/addons.json
There's no reason to get the name of the user, you can always just use ~/
or $HOME
to get the home directory. The name of the default profile is, likewise, unneeded. You probably only have one and its name will be RandomString.default
. If you have more than one, and different addons for each, this approach will list all of them. So, if you do have multiple profiles, you might want to add | uniq
to the above command to remove duplicates.
Explanation
-
grep -oP
: the-o
causesgrep
to only print the matched portion of the line and the-P
activates Perl Compatible Regular Expressions which are needed for the\K
(see below). -
},"name":"\K[^"]*
: match the longest stretch of non-"
characters ([^"]*
) that come right after},"name":
. The\K
means "ignore everything matched up to here" which, when combined with-o
, will cause only the part of the match after thename:":"
to be printed. -
~/
: this is your home directory.
Solution 3:
Following scriptlet is just a more-featureful version of @chaos's code. My motivations were
- I use more than one Firefox profile.
- I put my Firefox profiles in a different dir/folder than the default: see
FIREFOX_PROFILE_ROOT
in script/let, which you should probably edit (back to the default), or use the newerprofiles.ini
-parsing code (see link below). - I wanted to see more information about my add-ons, since I was having a problem that turned out to be extension-version-related.
- I just hadn't coded for a few days
:-)
You can also {see the latest version of this code, use the latest version as a downloadable script file} here. Note the newer code also parses profiles.ini
(using the profile paths you define there) rather than relying (as below) on you telling the code where to find your profiles.
### List add-ons in all local Firefox profiles. Requires:
### * users to know where they keep their Firefox profiles. TODO: parse `profiles.ini`
### * python (to parse the add-ons JSON)
### Tested on Linux with Python versions={2.7.9, 3.4.2}.
### Copyright (C) 2017 Tom Roche <[email protected]>
### This work is licensed under the Creative Commons Attribution 4.0 International License.
### To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/
#FIREFOX_PROFILE_ROOT="${HOME}/.mozilla/firefox" # default Firefox path, which ...
FIREFOX_PROFILE_ROOT="${HOME}/firefox" # ... I override, but you probably should not!
FIREFOX_ADDONS_FILENAME='addons.json' # default Firefox value
FIREFOX_ADDONS_FP_LIST='' # default empty
### find add-ons JSON files:
if [[ ! -r "${FIREFOX_PROFILE_ROOT}" ]] ; then
>&2 echo "ERROR: cannot read FIREFOX_PROFILE_ROOT='${FIREFOX_PROFILE_ROOT}', exiting ..."
else
FIREFOX_ADDONS_FP_LIST="$(find "${FIREFOX_PROFILE_ROOT}/" -type f -name "${FIREFOX_ADDONS_FILENAME}" | fgrep -ve 'blocklists')"
# echo -e "FIREFOX_ADDONS_FP_LIST=\n${FIREFOX_ADDONS_FP_LIST}" # debugging
if [[ ( -z "${FIREFOX_ADDONS_FP_LIST}" ) ||
( "$(echo ${FIREFOX_ADDONS_FP_LIST} | wc -l)" == '0' ) ]] ; then
>&2 echo "ERROR: found no add-ons files in Firefox profiles under '${FIREFOX_PROFILE_ROOT}', exiting ..."
else
for FIREFOX_ADDONS_FP in ${FIREFOX_ADDONS_FP_LIST} ; do
echo "${FIREFOX_ADDONS_FP} contains:"
### Parse add-ons file using python, so
### * gotta export the envvar
export FIREFOX_ADDONS_FP
### * indenting becomes important
python -c '
import json, os
with open(os.environ.get("FIREFOX_ADDONS_FP")) as addons_file:
addons_data = json.load(addons_file)
for (i, addon) in enumerate(addons_data["addons"]):
print("add-on name=" + addon["name"])
print(" version=" + addon["version"])
print(" URI=" + addon["learnmoreURL"])
print("") # newline
'
echo # newline
done
fi
fi