Created
April 16, 2017 05:32
-
-
Save harai/0b8566eda362def35e8be9b7a752d0af to your computer and use it in GitHub Desktop.
Sort Firefox container tab items
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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