Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Sort Firefox container tab items
#!/usr/bin/env python3
import json
import glob
from os import path
def get_jsonpath():
homedir = path.expanduser('~')
profiledirs = glob.glob('{}/.mozilla/firefox/*.default'.format(homedir))
if len(profiledirs) == 0:
raise ValueError('Cannot find profile directory')
if 1 < len(profiledirs):
raise ValueError('There are more than one default directory')
return '{}/containers.json'.format(profiledirs[0])
def get_container_config(jsonpath):
with open(jsonpath, 'r', encoding='UTF-8') as f:
return json.load(f)
def set_container_config(jsonpath, container_config):
with open(jsonpath, 'w', encoding='UTF-8') as f:
json.dump(container_config, f)
def sort_containers(container_config):
container_config['identities'] = sorted(
container_config['identities'], key=lambda i: i['name'])
return container_config
def main():
jsonpath = get_jsonpath()
container_config = get_container_config(jsonpath)
set_container_config(jsonpath, sort_containers(container_config))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment