Converting Qutebrowser bookmarks to w3m bookmarks


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:


touch ~/.w3m/bookmark.html

echo "<html><head><title>Bookmarks</title></head>
<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
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
done < ~/.qutebrowser/bookmarks/urls 

echo "</ul>
</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: Create LaTeX tables online R Basics Workshop - Home TexCount Snazzy Maps - Free Styles for Google Maps Protected Planet 

while .qutebrowser/quickmarks looks like this:

Google Keep
Google Photos