Skip to content

Instantly share code, notes, and snippets.

@blueforesticarus
Created March 1, 2024 02:54
Show Gist options
  • Save blueforesticarus/edab1c28fa0ee1794e6f6890e859145b to your computer and use it in GitHub Desktop.
Save blueforesticarus/edab1c28fa0ee1794e6f6890e859145b to your computer and use it in GitHub Desktop.
nushell script to parse (and interactively select using skim) brave browser history and bookmarks
#!/usr/bin/env nu
let BRAVE = ( glob ~/.config/BraveSoftware/Brave-Browser/Default/).0
def _history [] {
# make a copy of the history db, because it is locked when brave is open
let p = (mktemp -t)
cp $"($BRAVE)/History" $p
open $p
| query db "SELECT * from urls"
| sort-by last_visit_time
| select url title
}
def "main history" [] {
_history | to tsv -n
}
def "main history menu" [--query="", --filter=".", exec="echo"] {
^$exec ( _history | to tsv -n | rg $filter | tac | sk -q $query --reverse | from tsv -n | get column1.0 )
}
def _bookmarks [] {
jq '.roots[] | recurse({parent: [.parent[]?, .name]} + .children[]? ) | select(.type == "url") ' $"($BRAVE)/Bookmarks"
| jq -s
| from json
| select parent name url
| update parent { str join "/" }
}
def "main bookmarks" [] {
_bookmarks | to tsv -n
}
def "main bookmarks menu" [--filter=".", --query="", exec?="echo"] {
^$exec (_bookmarks | to tsv -n | rg $filter | sk -q $query --reverse | from tsv -n | get column3.0)
}
def main [] {
help browser
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment