#! /bin/sh

# Script to generate textual file from places.sqlite DB
# Copyright (C) 2009 Matous J. Fialka, <http://mjf.cz/>
# Released under the terms of The MIT License

# Hint: bm ~/.conkeror.mozdev.org/conkeror/xxxxxxxx.default/places.sqlite | less
# Note: this script is crap!

if [ "|"$1"|" == "||" ]; then
	exit 1
fi

if [ -r $1 ]; then
	cp $1 /tmp/places.sqlite.tmp || exit 2
fi

sqlite3 /tmp/places.sqlite.tmp '
	SELECT b.id, p.url, p.title, b.title
	FROM moz_bookmarks
	b INNER JOIN moz_places p ON b.fk = p.id
	ORDER BY b.id DESC;'

if [ -w /tmp/places.sqlite.tmp ]; then
	rm -f /tmp/places.sqlite.tmp || exit 3
fi

exit 0