Firefox tabs git repo

From WTFwiki
Jump to navigation Jump to search

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

Scripts

Cron job:

# Firefox tabs backup
50 2 * * *      /home/stian/bin/cron-tabdump.sh

Looks like:

#!/bin/sh

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:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import os, glob, sys, json, subprocess

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

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."
        sys.exit(1)

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']:
            continue
        cur = tab['entries'][-1]
        url = cur['url']
        title = cur['title'] if 'title' in cur else ''
        if includetitle:
            out = "\t" + url + "\t" + title
        else:
            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.