57 lines
1.9 KiB
Bash
Executable file
57 lines
1.9 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
# Interactively select (in skim) bookmarks to open from Firefox or
|
|
# Chrome/Chromium (depends on $BROWSER). Should work on Linux and MacOS.
|
|
#
|
|
# requires: sqlite3, jq (if you use chrome/chromium)
|
|
|
|
sep='{{::}}'
|
|
|
|
_do_rofi() {
|
|
for url in $(awk -F "${1:-$sep}" '{printf "%s, %s\n", $1, $2}' | rofi -dmenu -p 'bookmarks > ' -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
|
|
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 mb.title, mp.url FROM moz_bookmarks mb \
|
|
INNER JOIN moz_places mp ON mp.id = mb.fk \
|
|
WHERE mb.type = 1 AND mb.title IS NOT NULL \
|
|
ORDER BY mp.frecency DESC" | _do_rofi
|
|
break
|
|
fi
|
|
done
|
|
;;
|
|
qutebrowser)
|
|
sed -e 's/ /{{::}}/' urls | awk -F'{{::}}' '{printf "%s{{::}}%s\n", $2, $1}' | _do_rofi
|
|
;;
|
|
*)
|
|
for dir in ~/.config/google-chrome/Default ~/.config/chromium/Default ~/Library/Application\ Support/Google/Chrome/Default; do
|
|
# requires jq
|
|
if [[ -f "$dir/Bookmarks" ]]; then
|
|
jq -r '.. | [.name, .url]? | @tsv' "$dir/Bookmarks" | \
|
|
sed '/^[ \t]*$/d;/\t$/d;/\tchrome:\/\//d' | \
|
|
_do_rofi "\t"
|
|
break
|
|
fi
|
|
done
|
|
;;
|
|
esac
|