#!/bin/bash
#                       /usr/local/bin/bookmarksbydate
#  http://crystalfaeries.net/posix/bin/bookmarksbydate
# celeste:crystalfaery 2017-09-24 06:27:19+00:00
# original version from http://commandlinefu.com
# list firefox bookmarks by date in format: "dateAdded	url"

if [ $# -eq 0 ]
then	# called with no arguments (usually by crontab):
	#55 01 * * * /usr/local/bin/bookmarksbydate > /home/crystalfaeries.net/src/.bookmarksbydate.`/bin/hostname`.txt

	# generate the text file from the database
	sqlite3	${HOME}/.mozilla/firefox/*.[dD]efault/places.sqlite				\
		"SELECT strftime ('%Y-%m-%d.%H-%M-%S', dateAdded/1000000, 'unixepoch', 'localtime'),url FROM moz_places, moz_bookmarks WHERE moz_places.id = moz_bookmarks.fk ORDER BY dateAdded;"					|	\
		sed 's/|/	/g'	|	grep -v 'place:'			>	\
		/home/crystalfaeries.net/src/.bookmarksbydate.`/bin/hostname`.txt

else	# this is user requesting to view the daily file manually for review
	cut -f2- /home/crystalfaeries.net/src/.bookmarksbydate.`/bin/hostname`.txt	|	\
	while read URL
	do
		echo "viewing:	${URL}"
		firefox	       "${URL}"
		echo -n	"view next older bookmark?(Y/n):	"
		read disposition < /dev/tty
		case "${disposition}" in
no)		exit 0;;
n)		exit 0;;
*)		;;
		esac
	done
fi
# Update ToDo copy of alphabetical bookmarks
rsync -auvH	${HOME}/.mozilla/firefox/*.default/bookmarks.html /home/crystalfaeries.net/src/.bookmarks.html >& /dev/null
exit $?



syntax highlighted by Code2HTML, v. 0.9.1