Converting Qutebrowser bookmarks to w3m bookmarks

2018-12-01

I use Qutebrowser as my primary web browser, but I also really like using w3m for super fast text-based browsing when I’m working mostly in the terminal. As a bit of practice in writing bash scripts, I figured I would try to write a script which constructed a w3m style bookmark.html from my Qutebrowser formatted bookmarks/urls and quickmarks, because confusingly, Qutebrowser uses two files for bookmarks, with different formatting. This is what I came up with:

#!/bin/bash

touch ~/.w3m/bookmark.html

echo "<html><head><title>Bookmarks</title></head>
<body>
<h1>Quickmarks</h1>
<ul>" > ~/.w3m/bookmark.html

while read line; do
    if [[ $line != *"qute"* ]]; then
        url=$(echo $line | sed 's@.* @@')
        desc=$(echo $line | sed 's/\(.*\) .*/\1/') 
        echo "<li><a href=\"$url\">$desc</a>" >> ~/.w3m/bookmark.html
    fi
done < ~/.qutebrowser/quickmarks 

echo "</ul>" >> ~/.w3m/bookmark.html

echo "<h1>Other bookmarks</h1>
<ul>" >> ~/.w3m/bookmark.html

while read line; do
    if [[ $line != *"qute"* ]]; then
        url=$(echo $line | cut -d " " -f 1) 
        desc=$(echo ${line#* }) 
        echo "<li><a href=\"$url\">$desc</a>" >> ~/.w3m/bookmark.html
    fi
done < ~/.qutebrowser/bookmarks/urls 

echo "</ul>
</body>
</html>" >> ~/.w3m/bookmark.html

Firstly it creates a new bookmark.html, then echos some preamble HTML, then loops through each line of quickmarks then urls, cutting the line into the URL and the description of that URL, and forwards it to bookmark.html, then it puts in the footer HTML material. Importantly, it doesn’t include any bookmarks with the string qute in them, which all refer to Qutebrowser only special URIs, it does this with an if statement if [[ $line != *"qute"* ]]; then.

In w3m, I can then open bookmark.html with Esc-b.

For the record, .qutebrowser/bookmarks/urls looks like this:

http://www.tablesgenerator.com/ Create LaTeX tables online 
http://rbasicsworkshop.weebly.com/ R Basics Workshop - Home  
http://app.uio.no/ifi/texcount/online.php TexCount 
https://snazzymaps.com/ Snazzy Maps - Free Styles for Google Maps 
http://www.protectedplanet.net/ Protected Planet 

while .qutebrowser/quickmarks looks like this:

Gmail https://mail.google.com/mail/u/0/h/
Google Keep https://keep.google.com/
Google Photos https://photos.google.com/
YouTube http://www.youtube.com/