Firefox tabs git repo

From WTFwiki
Jump to navigation Jump to search

How to commit your Firefox tabs to a git repo automatically.


Cron job:

# Firefox tabs backup
50 2 * * *      /home/stian/bin/

Looks like:


cd ~/config/tabdump
~/bin/tabdump -t >tabdump
git diff --quiet && exit 0
git add tabdump
git commit -q -m "cron autocommit $(date -I)"

And tabdump:

# -*- coding: utf-8 -*-

import os, glob, sys, json, subprocess

    (profile,) = glob.glob(os.path.expanduser("~/.mozilla/firefox/*.default"))
    print >>sys.stderr, "No profile or multiple default profiles"

includetitle = False

if len(sys.argv) > 1:
    if sys.argv[1] == '-t':
        includetitle = True
    elif sys.argv[1] == '-h':
        print >>sys.stderr, "Usage: %s [-h] [-t]" % sys.argv[0]
        print >>sys.stderr, "   -h   Help."
        print >>sys.stderr, "   -t   Include titles."

fn = os.path.join(profile, "sessionstore-backups", "recovery.jsonlz4")
js = json.loads(subprocess.check_output(['/home/stian/down/dejsonlz4/dejsonlz4', fn]))

wcount = 0
for window in js['windows']:
    print "Window", wcount
    wcount += 1
    for tab in window['tabs']:
        if not tab['entries']:
        cur = tab['entries'][-1]
        url = cur['url']
        title = cur['title'] if 'title' in cur else ''
        if includetitle:
            out = "\t" + url + "\t" + title
            out = "\t" + url
        print out.encode('utf-8')

You need to install the dejsonlz4 command from [1] because when mozilla added compression to it they decided in their infinite wisdome to use a unique file format that no standard tool can read.