DEV Community

lotusirous
lotusirous

Posted on

FUZZY FINDING YOUR BOOKMARKS

Have you ever felt overwhelmed by your bookmarks, desperately trying to find
that one elusive link? If so, you're not alone. Many people struggle to keep
their bookmarks organized and accessible.

Major browsers like Brave and Chrome offer a folder-based organization system,
which can quickly become unwieldy. Even when resorting to searching through
browser-specific URLs like brave://bookmarks/?q=<your keyword>, it often falls
short because you may not remember the exact title or link.

Bookmark's data structure

At its core, a bookmark is quite straightforward. It consists of three elements:
a title, a link to the webpage, and the action of opening that link. Here's a
simple breakdown:

  • Title: The name you've given to the bookmark (e.g., Google).
  • Link: The web address associated with the bookmark (e.g., http://google.com).
  • Open action: The action you want to perform when you click on the bookmark, which is usually to open the link.

Why not store your bookmarks in a text file instead ?

This may seem like a simple solution, but it offers several advantages over
traditional bookmark managers:

  • Simplified Search: It's much easier to search a text file for a specific keyword than it is to search through a tree-like structure like a folder hierarchy. You can use a variety of tools to search and filter your bookmarks, including regular expressions and fuzzy search.
  • Version control: A text file can be easily tracked by version control. This means that you can easily recover your bookmarks if something goes wrong, or if you want to revert to a previous version.
  • Direct Editing in Your Editor: You can modify your bookmarks directly in your text editor, such as Vim. This makes it incredibly convenient to update and organize your bookmarks with the tools you are already familiar with.
  • Fuzzy Finding for Titles and Links: With this method, you can search for your bookmarks using either the title or the link. This is a significant improvement over traditional bookmark managers, which typically only allow you to search by title.

Here's a simple representation of how it looks:

Google |https://google.com
Youtube |https://youtube.com
Enter fullscreen mode Exit fullscreen mode

We use the pipe character (|) as our delimiter because it's not part of URI standards (RFC 3986). Thus, it doesn't clash with bookmark titles or URLs, and improves readability. While it's not an official URI standard delimiter, its adoption in this context is a convention that enhances bookmark management.

By storing this content in a file $HOME/.bookmarks, you gain the ability to
track and search for bookmarks by title or link. Additionally, macOS supports
opening links in your default browser by default. And to make things even
simpler, you can achieve all this with a single-line solution:

alias bm="cat ~/.bookmarks |fzf | cut -d '|' -f 2 | awk '{\$1=\$1;print}' |xargs open"
Enter fullscreen mode Exit fullscreen mode

If you need a practical solution for better bookmark management, give it a try.

Top comments (0)