make getpeername() return the original socket address which before it was intercepted
[hband-tools.git] / user-tools / moz_bookmarks
blob785ad0fbc1f9720ebab9dd0feb6b8ec9928ae7bb
1 #!/bin/bash
3 true <<EOF
4 =pod
6 =head1 NAME
8 moz_bookmarks - Read Mozilla bookmarks database and display titles and URLs line-by-line
10 =cut
12 EOF
15 set -e
16 set -o pipefail
17 set -u
19 indent()
21 sed -e 's/^/ /'
25 cd ~/.moonchild\ productions/pale\ moon/
26 cd *.default
27 dbfile=places.sqlite
30 sqlite3 -list "$dbfile" "SELECT 'bookmark', id, parent, fk, title FROM moz_bookmarks;
31 SELECT 'place', NULL, NULL, id, url FROM moz_places;
32 SELECT 'feed', item_id, NULL, NULL, content FROM moz_items_annos WHERE anno_attribute_id=(SELECT id FROM moz_anno_attributes WHERE name='livemark/feedURI')" |\
34 declare -A place_ids
35 declare -A parent_ids
36 declare -A titles
37 declare -A urls
38 declare -A bm_urls
40 while read -r type bookmark_id parent_id place_id content
42 case "$type" in
43 bookmark)
44 place_ids[$bookmark_id]=$place_id
45 parent_ids[$bookmark_id]=$parent_id
46 titles[$bookmark_id]=$content
48 place)
49 urls[$place_id]=$content
51 feed)
52 bm_urls[$bookmark_id]=$content
54 esac
55 done
57 show_bookmarks()
59 local parent_id=$1
60 local place_id
61 local bookmark_id
62 local title
63 local url
65 for bookmark_id in "${!parent_ids[@]}"
67 if [ ${parent_ids[$bookmark_id]} = $parent_id ]
68 then
69 title=${titles[$bookmark_id]}
70 echo "${title:-(no title)}"
72 set +u
73 url=${bm_urls[$bookmark_id]}
74 set -u
75 if [ -z "$url" ]
76 then
77 place_id=${place_ids[$bookmark_id]}
78 if [ "$place_id" != NULL ]
79 then
80 url=${urls[$place_id]}
83 if [ -n "$url" ]
84 then
85 echo "$url"
88 show_bookmarks $bookmark_id | indent
90 echo
92 done
95 parent_id=0
96 show_bookmarks $parent_id