helm/bin/rofi/history

60 lines
2 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
# Interactively select (in skim) an url from Firefox/Chrome/Chromium history to
# open in your browser (depends on $BROWSER). Should work on Linux and MacOS.
#
# requires: sqlite3
sep='{{::}}'
_do_rofi() {
for url in $(awk -F "${1:-$sep}" '{printf "%s, %s\n", $1, $2}' | rofi -dmenu -p='history > ' -multi-select | sed 's#.*\(https*://\)#\1#'); do
if command -v "$BROWSER" >/dev/null; then
$BROWSER "$url" &
elif command -v open >/dev/null; then
open "$url" &
else
xdg-open "$url" &
fi
done
}
case ${BROWSER:-firefox} in
qutebrowser)
sqlite3 -separator $sep "$XDG_DATA_HOME/qutebrowser/history.sqlite" \
"SELECT title, url FROM History \
WHERE title != '' \
GROUP BY url \
ORDER BY atime DESC" | _do_rofi
;;
firefox)
for dir in ~/.mozilla/firefox/*.default \
$XDG_CONFIG_HOME/firefox/.mozilla/firefox/*.default \
$XDG_DATA_HOME/mozilla/firefox/*.default \
~/Library/Application\ Support/Firefox/Profiles/*.default; do
if [[ -d "$dir" ]]; then
# The db can be locked from time to time. This is inefficient, but
# places.sqlite is usually under 30mb so this should be instant, and
# /tmp is cleared at boot so...
cp "$dir/places.sqlite" "/tmp/places.sqlite"
sqlite3 -separator $sep "/tmp/places.sqlite" \
"SELECT DISTINCT title, url FROM moz_places \
WHERE title IS NOT NULL \
ORDER BY last_visit_date DESC" | _do_rofi
break
fi
done
;;
*)
for dir in ~/.config/google-chrome/Default ~/.config/chromium/Default ~/Library/Application\ Support/Google/Chrome/Default; do
if [[ -f "$dir/History" ]]; then
cp -f "$dir/History" "/tmp/_h"
sqlite3 -separator $sep "/tmp/_h" \
"SELECT substr(title, 1, $((COLUMNS / 3))), url \
FROM urls ORDER BY last_visit_time DESC" | _do_rofi
break
fi
done
;;
esac