Storing Bookmarks on the Filesystem

Updated: 2012-04-18

About

I have noticed that my hierarchy of browser bookmarks looks a lot like my /home/user filesystem hierarchy. What is the point in maintaining two separate but similar hierarchies? If my bookmarks lived in my regular /home/user hierarchy, bookmark management would be easier. Bookmarks related to eg. a project, would actually exist and be manipulated in the same directory as regular files. Bookmarks could be listed, renamed, and loaded more efficiently: in the shell.

bookmarks-to-tree.py

The bookmarks-to-tree.py script reads a Netscape style bookmarks.html file on standard input and writes bookmark files to a folder. You can merge the resulting bookmark tree into your /home/user hierarchy. It supports either classic InternetExplorer bookmarks (very simple, easy to parse) or desktop link files (slightly better supported in GNU/Linux but less convenient due to internationalization support).

Dependencies: python-argparse, python-bs4

$ bookmarks-to-tree.py --help
usage: bookmarks-to-tree.py [-h] [-o OUTDIR] [-t {ie,desktop}]

Converts Netscape style bookmarks html from stdin to a directory tree.

optional arguments:
  -h, --help            show this help message and exit
  -o OUTDIR, --outdir OUTDIR
                        Set output directory; must not exist (by default, a
                        new folder in the current directory)
  -t {ie,desktop}, --type {ie,desktop}
                        Set output type; 'ie' for simple IE-style bookmarks
                        (the default), or 'desktop' for freedesktop link
                        files.

Remember to always verify output.

Using with uzbl

Now uzbl (for example) can be set up to save to and load bookmarks from those bookmark files. These 2 shell scripts are intended to be used with uzbl, bound to keys in the configuration.

Dependencies: zenity

Replacement for $HOME/.local/share/uzbl/scripts/insert_bookmark.sh: insert.sh

Replacement for $HOME/.local/share/uzbl/scripts/load_url_from_bookmarks.sh: load.sh

bookmarks-from-tree.py

If you are saving bookmarks to your /home/user, you might want to convert those bookmarks back into a Netscape style HTML file for use with a typical browser. The bookmarks-from-tree.py script will do that for you.

Dependencies: python-argparse

$ bookmarks-from-tree.py --help
usage: bookmarks-from-tree.py [-h] [-i INDIR] [-t {ie,desktop}] [-H]

Converts a directory tree with bookmark files to Netscape style bookmarks html
on stdout.

optional arguments:
  -h, --help            show this help message and exit
  -i INDIR, --indir INDIR
                        Set input directory; will be searched for bookmark
                        files; default is the current directory
  -t {ie,desktop}, --type {ie,desktop}
                        Set type of bookmarks to search for; "ie" for simple
                        IE-style bookmarks (ending with .url), or "desktop"
                        for freedesktop link files (ending with .desktop);
                        "ie" is the default
  -H, --hidden          Include hidden files and directories (those beginning
                        with ".") when searching (default is to ignore)

Remember to always verify output. When parsing desktop files, the filenames
are used rather than the Name fields.