Skip to content

Instantly share code, notes, and snippets.

@harai
Created April 16, 2017 05:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harai/0b8566eda362def35e8be9b7a752d0af to your computer and use it in GitHub Desktop.
Save harai/0b8566eda362def35e8be9b7a752d0af to your computer and use it in GitHub Desktop.
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