Firefox tabs git repo
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/env python3
import os, glob, sys, json, subprocess
try:
(profile,) = glob.glob(os.path.expanduser("~/.mozilla/firefox/*.default"))
except:
print("No profile or multiple default profiles", file=sys.stderr)
sys.exit(1)
includetitle = False
if len(sys.argv) > 1:
if sys.argv[1] == '-t':
includetitle = True
elif sys.argv[1] == '-h':
print(f"Usage: {sys.argv[0]} [-h] [-t]\n"
" -h Help.\n"
" -t Include titles.", file=sys.stderr)
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)
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.