add firefox history fuzzy finder script

main
earnest ma 2022-05-19 22:04:07 -04:00
parent ec40e06339
commit 00e820af2b
Signed by: earnest ma
GPG Key ID: A343F43342EB6E2A
1 changed files with 61 additions and 0 deletions

61
bin/.local/bin/ffhist Executable file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env bash
# From https://gist.github.com/dshnkao/10865f32d69e40dc591e08e3af970e9d
tmpfile=$(mktemp /tmp/ffhist.XXXXX)
cp -f ~/Library/Application\ Support/Firefox/Profiles/qdk1f64u.default-release/places.sqlite $tmpfile
DB_PATH="$tmpfile"
# 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=fzf
# 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
rm "$tmpfile"