dmenu-bookmarks


Using browser bookmarks in dmenu

If you want to access bookmarks from dmenu, you can do so like this:

First, you'll create a directory to hold the script and a file for your bookmarks (URLs). We'll create a file to store urls and one to store the script. In my case, I'll create it in my dwm directory.

$ mkdir ~/.config/dwm/bookmarks && cd ~/.config/dwm/bookmarks && touch urls dmenu-bookmarks.sh && chmod +x dmenu-bookmarks.sh

Now we can add bookmarks to the urls file. For example:

DuckDuckGo https://duckduckgo.com GitHub https://github.com

Next, let's write the script.

#!/bin/bash
BOOKMARKS=$(cut -d' ' -f1 ~/.config/dwm/bookmarks/urls)
BOOKMARK=$(echo "$BOOKMARKS" | dmenu -i -p "Select Bookmark:")
URL=$(grep "^$BOOKMARK " ~/.config/dwm/bookmarks/urls | cut -d' ' -f2-)
[ -n "$URL" ] && xdg-open "$URL"

This script displays all the titles of the bookmarks in dmenu. Once you select one, it grabs the url and opens it in your default browser.

If you're using dwm, make the following changes: In dwm's config.h, we'll now add the command to execute the script:

static const char *bookmarkcmd[] = { "/home/user/.config/dwm/bookmarks/dmenu-bookmarks.sh", NULL };

Now we can add the keybinding:

{ MODKEY, XK_b, spawn, {.v = bookmarkcmd } },

After everything is done, you should recompile dwm.

# make clean install

After restarting your X session, you should be able to run the script.