aboutsummaryrefslogtreecommitdiff
path: root/export-firefox-bookmarks
blob: 45878dd1654398b821dac1099ad725cc503556f2 (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
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash
#
# Export Mozilla Firefox bookmarks.
# Based on https://github.com/pirate/ArchiveBox/blob/master/bin/export_browser_history.sh
#

# Parameters
BASENAME="`basename $0`"
BASEDIR="$HOME/.mozilla/firefox"
PROFILES="$BASEDIR/profiles"
PROFILE="$1"
#SECTION="moz_${2:-bookmarks}"

# Export from a single database
function export_firefox_bookmark {
  sqlite3 $1 "SELECT \"[\" || group_concat(json_object('timestamp', b.dateAdded, 'description', b.title, 'href', f.url)) || \"]\" FROM moz_bookmarks AS b JOIN moz_places AS f ON f.id = b.fk"
}

# Check
#if [ ! -e "$BASEDIR/profiles.ini" ]; then
#  echo "$BASENAME: not found: $BASEDIR/profiles.ini"
#  exit 1
#fi

#PROFILES="grep "^Name=" $BASEDIR/profiles.ini | cut -d = -f 2 | xargs"

# There might be many places.sqlite on many profiles
if [ -z "$PROFILE" ]; then
  find $BASEDIR -name places.sqlite | while read file; do \
    export_firefox_bookmark $file
  done
else
  # Assumption: when a $PROFILE is given, search at $PROFILES
  if [ -e "$PROFILES/$PROFILE/places.sqlite" ]; then
    export_firefox_bookmark $PROFILES/$PROFILE/places.sqlite
  else
    echo "$BASENAME: file not found: $PROFILES/$PROFILE/places.sqlite"
    exit 1
  fi
fi