summaryrefslogtreecommitdiffstats
path: root/dump-ff-history
blob: c171aa346e72e238bd5d63e6e049bdc06fe31a7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash

TMPDIR="$(mktemp -d "/tmp/${0##*/}.XXXXXX")"
trap "rm -rf '${TMPDIR}'" EXIT TERM

cp -n ~/.mozilla/firefox/*.default/places.sqlite* "$TMPDIR"

sqlite_opts=()

case $MODE in
	zsh-history-compat)
		select_fields="visit_date/1000000 AS visit_date, url, title"
		sqlite_opts=(-separator ' | ')
		;;
	*) select_fields="datetime(visit_date/1000000,'unixepoch', 'localtime') AS visit_date, url, title";;
esac

output_filter() {
	if [[ $MODE == 'zsh-history-compat' ]]; then
		sed -r 's#^([0-9]+) \| (.*)$#: \1:0;\2#'
	else
		cat
	fi
}

sqlite3 "${sqlite_opts[@]}" "$TMPDIR/places.sqlite" "SELECT $select_fields
FROM moz_places, moz_historyvisits
WHERE moz_places.id = moz_historyvisits.place_id AND visit_date/1000000 > $(date +%s -d "${1:-2 months ago}") AND visit_date/1000000 < $(date +%s -d "${2:-now}")
ORDER BY visit_date" | output_filter