Sorting Containers of Firefox Multi-Account Containers Add-on, using Perl

Do you use Firefox Multi-Account Containers add-on? If you do, do you create lots of containers and wish you could reorder the list of containers? Then this short post might be of interest to you.

As of this writing, the add-on does not provide a UI to do so (GitHub issue #1208). Google search landed me on the issue page and I saw a rather interesting PowerShell snippet to accomplish what I want. Basically to sort the containers you just need to sort the identity records in the containers.json file. Since I already wrote a couple of Firefox modules like Firefox::Util::Profile and App::FirefoxUtils, I thought I'd write the equivalent of the script in Perl.

The result: firefox-mua-sort-containers (source code). I believe the core logic of the code is as straightforward as the PowerShell version, with a few additional niceties:

It does not close Firefox automatically but just politely tells you that Firefox needs to stop running.

It backs up containers.json first.

It sports a --dry-run (-n) option to show you how the containers will be sorted, without actually modifying the file.

It allows easy sort specification using Sort::Sub.

Tab completion (activate using complete -C firefox-mua-sort-containers firefox-mua-sort-containers first; or see the documentation for more details).

Installation

To install the script:

% cpanm -n App::FirefoxMultiAccountContainersUtils

Please wait a few moment while the installer downloads and installs all the requirements.

Some examples

Sort by name:

% firefox-mua-sort-containers myprofile -n  ;# just show the sorted list, don't actually sort yet
% firefox-mua-sort-containers myprofile     ;# now sort it for real

Sort by length then name (yeah, just a useless example):

% firefox-mua-sort-containers myprofile --sort-sub by_several --first by_length --second by_name

Sort by name, but keep some containers I often use at the top:

% firefox-mua-sort-containers myprofile
% firefox-mua-sort-containers myprofile --sort-sub by_example --sort-arg example='container1,container2,container3'

Enjoy.

6 thoughts on “Sorting Containers of Firefox Multi-Account Containers Add-on, using Perl

  1. Hello I’ve got this error after I did cpanm -n App::FirefoxMultiAccountContainersUtils :
    ! Installing the dependencies failed: Installed version (0.001) of Firefox::Util::Profile is not in range ‘0.004’
    ! Bailing out the installation for App-FirefoxMultiAccountContainersUtils-0.003.

    Like

    • Sorry about that. Firefox::Util::Profile 0.004 was not uploaded to CPAN yet. It is now. Please try again and tell me if you still have problems. Note: should you need it, you can force to install version 0.004 of Firefox::Util::Profile by using: cpanm -n Firefox::Util::Profile@0.004

      Like

  2. Hello,

    Thanks for developing this sorting tool! I’m eager to tell my colleagues and friends about it … when I can get it to install.

    I’m attempting to install on OSX and getting a series of errors; the errors start at:

    “! Installing the dependencies failed: Module ‘Sah::Schema::unix::local_uid’ is not installed, Module ‘Perinci::CmdLine::Any’ is not installed, Module”

    And a series of lines similar to:

    “cannot unlink file for /Users/USERXX/.cpanm/work/1573594190.73636/Test-Needs-0.002006/Makefile: Permission denied at /usr/local/bin/cpanm line 549.
    cannot restore permissions to 0100644 for /Users/USERXX/.cpanm/work/1573594190.73636/Test-Needs-0.002006/Makefile: Permission denied at /usr/local/bin/cpanm line 549.

    I’m not sure what do do from here.

    Thanks!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s