From d492a84b6619be88f721c11280cd700634959290 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 25 Apr 2017 02:37:53 -0400 Subject: [PATCH] browser/firefox: rewrite bookmark/history scripts (text only) --- browser/firefox/aliases.zsh | 2 -- browser/firefox/bin/firefox-bookmarks | 11 ++--------- browser/firefox/bin/firefox-history | 11 ++--------- browser/firefox/bin/lib/FirefoxProfile.py | 24 ++++++++++------------- 4 files changed, 14 insertions(+), 34 deletions(-) delete mode 100644 browser/firefox/aliases.zsh diff --git a/browser/firefox/aliases.zsh b/browser/firefox/aliases.zsh deleted file mode 100644 index 20a5e724..00000000 --- a/browser/firefox/aliases.zsh +++ /dev/null @@ -1,2 +0,0 @@ -alias bm='ffbookmarks' -alias hist='ffhistory' diff --git a/browser/firefox/bin/firefox-bookmarks b/browser/firefox/bin/firefox-bookmarks index c97edf5e..c3e6cd87 100755 --- a/browser/firefox/bin/firefox-bookmarks +++ b/browser/firefox/bin/firefox-bookmarks @@ -1,14 +1,7 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 -import sys -from pyfzf import FzfPrompt from lib.FirefoxProfile import FirefoxProfile with FirefoxProfile.default() as ff: - choice = FzfPrompt().prompt(ff.bookmarks()) - if choice: - ff.browse("http" + choice[0].split(", http")[1]) - else: - print("Aborted") - sys.exit(1) + print("\n".join(ff.bookmarks())) diff --git a/browser/firefox/bin/firefox-history b/browser/firefox/bin/firefox-history index 08cb47c5..da309a43 100755 --- a/browser/firefox/bin/firefox-history +++ b/browser/firefox/bin/firefox-history @@ -1,14 +1,7 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python -import sys -from pyfzf import FzfPrompt from lib.FirefoxProfile import FirefoxProfile with FirefoxProfile.default() as ff: - choice = FzfPrompt().prompt(ff.history()) - if choice: - ff.browse("http" + choice[0].split(", http")[1]) - else: - print("Aborted") - sys.exit(1) + print("\n".join(ff.history())) diff --git a/browser/firefox/bin/lib/FirefoxProfile.py b/browser/firefox/bin/lib/FirefoxProfile.py index e88521ae..a482dd50 100644 --- a/browser/firefox/bin/lib/FirefoxProfile.py +++ b/browser/firefox/bin/lib/FirefoxProfile.py @@ -1,13 +1,8 @@ -#!/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) @@ -54,16 +49,17 @@ class FirefoxProfile: return self._process(self.cur.fetchall()) def _process(self, data): - lookup = {} - result = [] + title_lookup = {} + url_lookup = {} + ret = [] 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 + title = row[0].encode('utf-8').decode() + url = row[1].encode('utf-8').decode() + if url.startswith("http") and title not in title_lookup and url not in url_lookup: + title_lookup[title] = 1 + url_lookup[url] = 1 + ret.append("{}, {}".format(title, url)) + return ret def browse(self, url): if _platform.startswith("linux"):