Add browser/firefox topic + fzf-powered bookmarks/history fuzzy search scripts
This commit is contained in:
parent
2c839d909d
commit
2e95bff661
2
browser/firefox/aliases.zsh
Normal file
2
browser/firefox/aliases.zsh
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
alias bm='ffbookmarks'
|
||||||
|
alias hist='ffhistory'
|
13
browser/firefox/bin/ffbookmarks
Executable file
13
browser/firefox/bin/ffbookmarks
Executable file
|
@ -0,0 +1,13 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from pyfzf import FzfPrompt
|
||||||
|
from lib.FirefoxProfile import FirefoxProfile
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
ff = FirefoxProfile.default()
|
||||||
|
choice = FzfPrompt().prompt(ff.bookmarks())
|
||||||
|
if choice:
|
||||||
|
ff.open("http" + choice[0].split(", http")[1])
|
||||||
|
else:
|
||||||
|
print("Aborted")
|
13
browser/firefox/bin/ffhistory
Executable file
13
browser/firefox/bin/ffhistory
Executable file
|
@ -0,0 +1,13 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from pyfzf import FzfPrompt
|
||||||
|
from lib.FirefoxProfile import FirefoxProfile
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
ff = FirefoxProfile.default()
|
||||||
|
choice = FzfPrompt().prompt(ff.history())
|
||||||
|
if choice:
|
||||||
|
ff.open("http" + choice[0].split(", http")[1])
|
||||||
|
else:
|
||||||
|
print("Aborted")
|
71
browser/firefox/bin/lib/FirefoxProfile.py
Normal file
71
browser/firefox/bin/lib/FirefoxProfile.py
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import sqlite3 as sqlite
|
||||||
|
import os
|
||||||
|
from glob import glob
|
||||||
|
from pyfzf import FzfPrompt
|
||||||
|
from sys import platform as _platform
|
||||||
|
|
||||||
|
fzf = FzfPrompt()
|
||||||
|
|
||||||
|
class FirefoxProfile:
|
||||||
|
def __init__(self, dbfile):
|
||||||
|
self.db = sqlite.connect(dbfile)
|
||||||
|
self.cur = self.db.cursor()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def default():
|
||||||
|
dbfile = None
|
||||||
|
paths = ["~/.mozilla/firefox", "~/Library/Application Support/Firefox/Profiles"]
|
||||||
|
while paths:
|
||||||
|
path = os.path.expanduser(paths.pop())
|
||||||
|
files = glob('{}/*.default/places.sqlite'.format(path))
|
||||||
|
if files:
|
||||||
|
dbfile = files[0]
|
||||||
|
break
|
||||||
|
if not dbfile:
|
||||||
|
raise Exception("No places.sqlite file")
|
||||||
|
return FirefoxProfile(dbfile)
|
||||||
|
|
||||||
|
def bookmarks(self):
|
||||||
|
self.cur.execute(
|
||||||
|
'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'
|
||||||
|
)
|
||||||
|
return self._process(self.cur.fetchall())
|
||||||
|
|
||||||
|
def history(self):
|
||||||
|
self.cur.execute(
|
||||||
|
'SELECT DISTINCT title, url ' +
|
||||||
|
'FROM moz_places ' +
|
||||||
|
'WHERE title IS NOT NULL '
|
||||||
|
'ORDER BY last_visit_date DESC'
|
||||||
|
)
|
||||||
|
return self._process(self.cur.fetchall())
|
||||||
|
|
||||||
|
def _process(self, data):
|
||||||
|
lookup = {}
|
||||||
|
result = []
|
||||||
|
for row in data:
|
||||||
|
title = (row[0] or "").encode('utf-8').strip()
|
||||||
|
url = (row[1] or "").encode('utf-8').strip()
|
||||||
|
key = ", ".join((title, url))
|
||||||
|
if key not in lookup and row[1].startswith("http"):
|
||||||
|
lookup[key] = 1
|
||||||
|
result.append(key)
|
||||||
|
return result
|
||||||
|
|
||||||
|
def open(self, url):
|
||||||
|
if _platform.startswith("linux"):
|
||||||
|
os.system('xdg-open "{}"'.format(url))
|
||||||
|
elif _platform == "darwin":
|
||||||
|
os.system('open "{}"'.format(url))
|
||||||
|
else:
|
||||||
|
raise Exception("What you doin' fool")
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self.db.close()
|
0
browser/firefox/bin/lib/__init__.py
Normal file
0
browser/firefox/bin/lib/__init__.py
Normal file
12
browser/firefox/install
Executable file
12
browser/firefox/install
Executable file
|
@ -0,0 +1,12 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
case $OSTYPE in
|
||||||
|
darwin*)
|
||||||
|
brew cask install firefox
|
||||||
|
;;
|
||||||
|
linux*)
|
||||||
|
if [[ -f /etc/arch-release ]]; then
|
||||||
|
sudo pacman --needed --noconfirm -S firefox
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
Loading…
Reference in a new issue