From 706aa20e438bb05f50afba4130b091d264e9bf92 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Wed, 30 Oct 2024 18:25:23 +0530 Subject: Use any pinentry again with gpg --- config/qutebrowser/config.py | 7 +- config/qutebrowser/userscripts/readability-js | 158 ++++++++++++++++++++++++++ home.nix | 5 +- packages/anypinentry/pkg.nix | 22 ++-- 4 files changed, 181 insertions(+), 11 deletions(-) create mode 100755 config/qutebrowser/userscripts/readability-js diff --git a/config/qutebrowser/config.py b/config/qutebrowser/config.py index c65a9a2..fdf107e 100644 --- a/config/qutebrowser/config.py +++ b/config/qutebrowser/config.py @@ -342,10 +342,15 @@ nmap(localleader + 'tm', 'mark-resource') # }}} #### Dev {{{ -nmap(leader + 'tr', 'config-source') # Reload config +# nmap(leader + 'tr', 'config-source') # Reload config nmap(leader + 'ti', 'devtools window') # Inspector nmap(leader + 'ts', 'view-source') # View page source +# Readbility {{{ +c.aliases['reading-mode'] = 'spawn --userscript readability-js'; +nmap(leader + 'tr', 'reading-mode') +# }}} + # Json formatter {{{ c.aliases['format-json'] = 'spawn --userscript format_json'; nmap(leader + 'tj', 'format-json') diff --git a/config/qutebrowser/userscripts/readability-js b/config/qutebrowser/userscripts/readability-js new file mode 100755 index 0000000..a326b04 --- /dev/null +++ b/config/qutebrowser/userscripts/readability-js @@ -0,0 +1,158 @@ +#!/usr/bin/env node +// +// # Description +// +// Summarize the current page in a new tab, by processing it with the standalone readability +// library used for Firefox Reader View. +// +// # Prerequisites +// +// - Mozilla's readability library (npm install -g @mozilla/readability) +// - Also available in the AUR as nodejs-readability-git +// - jsdom (npm install -g jsdom) +// - qutejs (npm install -g qutejs) +// +// - Ensure that node knows where to find your globally installed modules by adding +// the following to ~/.profile or /etc/profile: +// +// export NODE_PATH=$NODE_PATH:$(npm root -g) +// +// *Note*: On some Linux distros and macOS, it may be easier to set NODE_PATH using qutebrowser's +// qt.environ setting. For instance, if 'npm root -g' returns /usr/lib/node_modules, then run: +// +// :set qt.environ '{"NODE_PATH": "/usr/lib/node_modules"}' +// +// # Usage +// +// :spawn --userscript readability-js +// +// One may wish to define an easy to type command alias in qutebrowser's configuration file: +// c.aliases = {"readability" : "spawn --userscript readability-js", ...} + +const { Readability } = require('@mozilla/readability'); +const qute = require('qutejs'); +const JSDOM = require('jsdom').JSDOM; +const fs = require('fs'); +const path = require('path'); +const util = require('util'); + +const HEADER = ` + + + + + + %s + + + + + +

%s

+
From %s
+
+ %s + + +`; +const scriptsDir = path.join(process.env.QUTE_DATA_DIR, 'userscripts'); +const tmpFile = path.join(scriptsDir, '/readability.html'); + +if (!fs.existsSync(scriptsDir)) { + fs.mkdirSync(scriptsDir); +} + +let getDOM, domOpts, target; +// When hinting, use the selected hint instead of the current page +if (process.env.QUTE_MODE === 'hints') { + getDOM = JSDOM.fromURL; + target = process.env.QUTE_URL; +} +else { + getDOM = JSDOM.fromFile; + domOpts = { url: process.env.QUTE_URL, contentType: "text/html; charset=utf-8" }; + target = process.env.QUTE_HTML; +} + +getDOM(target, domOpts).then(dom => { + let reader = new Readability(dom.window.document); + let article = reader.parse(); + let subtitle = (article.siteName == null) ? new URL(process.env.QUTE_URL).hostname : article.siteName; + let content = util.format(HEADER, article.title, article.title, process.env.QUTE_URL, subtitle, article.content); + + fs.writeFile(tmpFile, content, (err) => { + if (err) { + qute.messageError([`"${err}"`]) + return 1; + } + // Success + qute.open(['-t', '-r', tmpFile]); + }) +}); diff --git a/home.nix b/home.nix index 31672dd..cd11198 100644 --- a/home.nix +++ b/home.nix @@ -99,9 +99,8 @@ in maxCacheTtl = 864000; defaultCacheTtl = 864000; enableSshSupport = false; - pinentryPackage = pkgs.pinentry-qt; - # pinentryFlavor = "qt"; - # pinentryFlavor = null; + # pinentryPackage = pkgs.pinentry-qt; + pinentryPackage = localPkgs.anypinentry; # extraConfig = '' # pinentry-program ${localPkgs.anypinentry}/bin/anypinentry # ''; diff --git a/packages/anypinentry/pkg.nix b/packages/anypinentry/pkg.nix index 7536594..89562b8 100644 --- a/packages/anypinentry/pkg.nix +++ b/packages/anypinentry/pkg.nix @@ -1,17 +1,25 @@ -{ stdenv, pkgs, dmenu ? (import ../default.nix { pkgs = pkgs; }).dmenu }: -with pkgs.lib; - +{ stdenv, pkgs, lib, dmenu ? (import ../default.nix { pkgs = pkgs; }).dmenu }: stdenv.mkDerivation rec { - name = "local-anypinentry-${version}"; - version = "0.0.0"; + pname = "anypinentry"; + version = "0.1.0"; + meta.mainProgram = "anypinentry"; src = ./source; - wrapperPath = makeBinPath ([ dmenu ]); + buildInputs = [ + dmenu + pkgs.getopt + pkgs.coreutils + pkgs.gnused + pkgs.gawk + pkgs.libnotify + ]; + nativeBuildInputs = [ pkgs.makeWrapper ]; unpackPhase = ''cp -r $src/* .''; installPhase = '' mkdir -p $out/bin; - cp $src/anypinentry $out/bin/ + cp $src/anypinentry $out/bin/; + wrapProgram "$out/bin/anypinentry" --prefix PATH : "/bin:${lib.makeBinPath buildInputs}"; ''; } -- cgit v1.3.1