Browsing Chrome bookmarks with fzf
2015. 04. 07.

In the last post, we looked at how we can integrate Chrome browsing history stored in SQLite database with fzf. In this post, we'll do it for bookmarks.

Chrome bookmarks in JSON format

Unlike browsing history, Chrome bookmarks are found in JSON format. It's stored in the same directory as the SQLite database file, and for OS X, the file is ~/Library/Application Support/Google/Chrome/Default/Bookmarks.

Chrome bookmarks can be organized in folders, so naturally the JSON representation of the bookmarks also has the corresponding recursive, hierarchical structure. If it was flat and simpler, we could have considered using jq, a handy command-line JSON processor, for processing the data but this case is a little beyond the scope of the tool's capability and we would have to resort to a scripting language with proper JSON support.

I chose Ruby, one that I'm most familiar with, for processing the JSON data and formatting it as the input to fzf. I'm not going to delve into the details of the implementation. It's just a basic JSON processing that can be written in any language and there's not much going on. Only that I took special care for CJK wide characters.

fzf integration

The complete script can be found here.

What's the most interesting about the script is that it starts as a bash script, but turns into a Ruby script. The reason the code is organized so is that I did not want to maintain two files, a Ruby script for processing JSON and a bash script for gluing it with fzf. Instead I used this special -x option of ruby command, which makes the interpreter ignore the lines in the file until #!ruby appears, so I can safely prepend the bash script to the file.

A few more things to mention:

» capture | close