#!/usr/bin/env bash # Interactively select (in fzf) bookmarks to open from Firefox or # Chrome/Chromium (depends on $BROWSER). Should work on Linux and MacOS. # # requires: sqlite3, jq (if you use chrome/chromium) [[ $OSTYPE == linux* ]] && open='xdg-open' || open='open' _do_fzf() { for url in $(awk -F "$1" '{printf "%s, %s\n", $1, $2}' | fzf --prompt='bookmarks > ' --multi | sed 's#.*\(https*://\)#\1#'); do $open "$url" & done } case ${BROWSER:-firefox} in firefox) for dir in ~/.mozilla/firefox/*.default ~/.config/firefox/.mozilla/firefox/*.default ~/Library/Application\ Support/Firefox/Profiles/*.default; do if [[ -d "$dir" ]]; then sep='{{::}}' sqlite3 -separator $sep "$dir/places.sqlite" \ "SELECT DISTINCT mb.title, mp.url FROM moz_bookmarks mb \ INNER JOIN moz_places mp ON mp.id = mb.fk \ WHERE mb.type = 1 AND mb.title IS NOT NULL \ ORDER BY mp.frecency DESC" | _do_fzf "$sep" break fi done ;; *) for dir in ~/.config/google-chrome/Default ~/.config/chromium/Default ~/Library/Application\ Support/Google/Chrome/Default; do # requires jq if [[ -f "$dir/Bookmarks" ]]; then jq -r '.. | [.name, .url]? | @tsv' "$dir/Bookmarks" | \ sed '/^[ \t]*$/d;/\t$/d;/\tchrome:\/\//d' | \ _do_fzf "\t" break fi done ;; esac