diff --git a/bin/.local/bin/ffhist b/bin/.local/bin/ffhist new file mode 100755 index 0000000..98bf2b7 --- /dev/null +++ b/bin/.local/bin/ffhist @@ -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"