2017-12-05 22:39:10 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-03-23 12:29:50 -07:00
|
|
|
# Interactively select (in skim) bookmarks to open from Firefox or
|
2017-12-05 22:39:10 -08:00
|
|
|
# Chrome/Chromium (depends on $BROWSER). Should work on Linux and MacOS.
|
|
|
|
#
|
|
|
|
# requires: sqlite3, jq (if you use chrome/chromium)
|
|
|
|
|
|
|
|
[[ $OSTYPE == linux* ]] && open='xdg-open' || open='open'
|
|
|
|
|
2018-03-23 12:29:50 -07:00
|
|
|
_do_sk() {
|
|
|
|
for url in $(awk -F "$1" '{printf "%s, %s\n", $1, $2}' | skim --prompt='bookmarks > ' --multi | sed 's#.*\(https*://\)#\1#'); do
|
2017-12-05 22:39:10 -08:00
|
|
|
$open "$url" &
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
case ${BROWSER:-firefox} in
|
|
|
|
firefox)
|
|
|
|
for dir in ~/.mozilla/firefox/*.default ~/.config/firefox/.mozilla/firefox/*.default ~/Library/Application\ Support/Firefox/Profiles/*.default; do
|
|
|
|
if [[ -d "$dir" ]]; then
|
|
|
|
sep='{{::}}'
|
|
|
|
sqlite3 -separator $sep "$dir/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 \
|
2018-03-23 12:29:50 -07:00
|
|
|
ORDER BY mp.frecency DESC" | _do_sk "$sep"
|
2017-12-05 22:39:10 -08:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
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' | \
|
2018-03-23 12:29:50 -07:00
|
|
|
_do_sk "\t"
|
2017-12-05 22:39:10 -08:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
esac
|