Skip to content

Instantly share code, notes, and snippets.

@rrrnld
Last active August 23, 2024 08:35
Show Gist options
  • Save rrrnld/79e92635cc8ec3d58e1ea3338ad0347f to your computer and use it in GitHub Desktop.
Save rrrnld/79e92635cc8ec3d58e1ea3338ad0347f to your computer and use it in GitHub Desktop.
Interacting with your Firefox bookmarks and history from the command line

Firefox History and Bookmark Command Line Interface

These scripts use fzf and sqlite to efficiently query your firefox history and bookmarks. This is heavily inspired by a post from the creator of fzf: https://junegunn.kr/2015/04/browsing-chrome-history-with-fzf/. fzf allows you to select multiple items and the results returned will be the URLs.

What Does It Look Like?

asciicast

Common Use Cases

Open a visited Web Page in a Browser

On Linux:

bhistory | xargs xdg-open

On macOS:

bhistory | xargs open

Copy the URLs of Selected Bookmarks into Your Clipboard

On Linux (with X11):

bbookmarks | xsel --clipboard -i

On macOS:

bbookmarks | pbcopy

Things to Consider

  • The firefox profile is matched with a glob wildcard (*). This will probably break if you use more than one profile.
  • The scripts are untested but should work on macOS; you need to change the profile path to ~/Library/Application\ Support/Firefox/Profiles
#!/usr/bin/env bash
# query all of your firefox bookmarks by tag, title or url
# idea from https://junegunn.kr/2015/04/browsing-chrome-history-with-fzf/
sep='{::}'
# this is rarely locked but still, safety first
cp ~/.mozilla/firefox/*/weave/bookmarks.sqlite /tmp
sqlite3 -separator $sep /tmp/bookmarks.sqlite \
'
SELECT i.title, REPLACE(GROUP_CONCAT(t.tag), ",", ", "), u.url FROM items i
JOIN urls u ON i.urlId = u.id
LEFT OUTER JOIN tags t ON i.id = t.itemId
GROUP BY t.itemId
' |
awk -F $sep '{printf "%-'$cols's \x1b[36m%-'$cols's \x1b[m%-'$cols's\n", $1, $2, $3}' |
sed -E 's/\x1b\[[0-9;]+m //g' |
fzf --ansi --multi |
grep -oP 'https?://.*$'
#!/usr/bin/env bash
# query all of your firefox history by visit date, title or url
# idea from https://junegunn.kr/2015/04/browsing-chrome-history-with-fzf/
sep='{::}'
cp ~/.mozilla/firefox/*/places.sqlite /tmp
sqlite3 -separator $sep /tmp/places.sqlite \
'
SELECT datetime(v.visit_date/1000000, "unixepoch"), p.title, p.url FROM moz_places p
JOIN moz_historyvisits v ON p.id = v.place_id
GROUP BY p.url
ORDER BY last_visit_date DESC
' |
awk -F $sep '{printf "%s \x1b[36m%s \x1b[m%s\n", $1, $2, $3}' |
sed -E 's/\x1b\[[0-9;]+m //g' |
fzf --ansi --multi |
grep -oP 'https?://.*$'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment