From 392727e1694bf69521adc4178bf98cb0d9992f9d Mon Sep 17 00:00:00 2001 From: dece Date: Mon, 29 Aug 2022 00:20:55 +0200 Subject: [PATCH] get-firefox-profiles --- get-firefox-profiles.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 get-firefox-profiles.py diff --git a/get-firefox-profiles.py b/get-firefox-profiles.py new file mode 100755 index 0000000..efc38fe --- /dev/null +++ b/get-firefox-profiles.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +import re +from argparse import ArgumentParser +from configparser import ConfigParser +from pathlib import Path + +profile_section_re = re.compile(r"Profile\d+") + +parser = ArgumentParser() +parser.add_argument("-p", "--path", help="get path for a profile name") +args = parser.parse_args() + +firefox_dir = Path.home() / ".mozilla" / "firefox" +config = ConfigParser() +config.read(firefox_dir / "profiles.ini") + +if profile_name := args.path: + for section in config.sections(): + if ( + profile_section_re.fullmatch(section) + and config[section]["Name"] == profile_name + ): + print(firefox_dir / config[section]["Path"]) + break + else: + exit("No profile with this name") +else: + for section in config.sections(): + if profile_section_re.fullmatch(section): + print(config[section]["Name"])