Skip to content

Instantly share code, notes, and snippets.

@dshnkao
Last active December 19, 2023 14:59
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dshnkao/10865f32d69e40dc591e08e3af970e9d to your computer and use it in GitHub Desktop.
Save dshnkao/10865f32d69e40dc591e08e3af970e9d to your computer and use it in GitHub Desktop.
open firefox history using fzf or rofi
#!/usr/bin/env bash
# Relying on rofi / fzf is a bit limited
# e.g
# umenu "places.sqlite" "rofi -dmenu --no-sort"
# umenu "places.sqlite" "fzf --no-sort --exact"
DB_PATH=${1:?ARG 1: path to firefox database}
FINDER=${2:?ARG 2: fzf or rofi}
QUERY="
SELECT
url, title FROM moz_places
WHERE
url NOT LIKE '%google%search%'
ORDER BY
visit_count DESC,
last_visit_date DESC;
"
SEP="∙"
ENTRY=$(
sqlite3 "$DB_PATH" "$QUERY" | \
sed -E 's/^https?:\/\///' | \
sed -E "s/\\/?\\|/ $SEP /" | \
sed -E "s/$SEP $//" | \
$FINDER
)
URL=$( echo "$ENTRY" | sed "s/$SEP.*//g" )
if [ "$URL" = "" ]; then
exit 0
fi
# google search if input end with .
if [ "${URL: -1}" = "." ]; then
SEARCH="${URL:: -1}"
URL="google.com/search?q=$SEARCH"
fi
case $(uname) in
'Linux')
xdg-open "https://$URL"
;;
'Darwin')
open "https://$URL"
;;
esac
@denisu
Copy link

denisu commented Aug 2, 2019

Neat idea, I like it!

@ddddavidee
Copy link

ddddavidee commented Apr 24, 2020

if you use call the function while firefox is open you'll get an error because the db is locked.
So I added something like:

tmpfile=$(mktemp /tmp/ffhist.XXXXX)

    cp -f ~/.mozilla/firefox/PROFILEPATH/places.sqlite $tmpfile

@mbjd
Copy link

mbjd commented Dec 19, 2023

you can circumvent the lock because you are not modifying the table; no need to copy the whole database. just replace your DB_PATH with:

"file:$DB_path?immutable=true"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment