User Tools

Site Tools


util:qutebrowser

qutebrowser

qutebrowser is based on qtwebengine and one of the better lightweight browser alternatives.

vim as external text box editor

This is simple:

config.py
c.editor.command = [ "urxvt", "-e", "vim", '{file}' ]
c.editor.encoding = "utf-8"

From a focussed text box, pressing '<CTRL>-e' then spawns a new terminal with the editor.

mpv as media player

Using mpv is a rather elegant way around advertisements in YT and other annoyances. The player is ideally called via umpv wrapper as that adds new videos to the running instance's playlist instead of spawning another one. In Gentoo, the wrapper is shipped when building with tools use-flag.

config.py
config.bind(",m", "spawn umpv {url}")
config.bind(",M", "hint links spawn umpv {hint-url}")
config.bind(";M", "hint --rapid links spawn umpv {hint-url}")

pass as password storage

To make use of stored logins in pass, install dmenu and tldextract then use qute-pass userscript.

Integration into qutebrowser like so:

config.py
config.bind('<z><l>', 'spawn --userscript qute-pass')
config.bind('<z><u><l>', 'spawn --userscript qute-pass --username-only')
config.bind('<z><p><l>', 'spawn --userscript qute-pass --password-only')
config.bind('<z><o><l>', 'spawn --userscript qute-pass --otp-only')

Stored logins in pass must have the URL somewhere in the path. Default is to use the leaf name as login and its content as password - may be customized, though.

Import from firefox

To import logins from firefox, they must be exported first. Since this is not easily possible anymore in newer versions, there is an add-on ff-password-exporter doing that. On older versions, CSV export is still functional.

For importing into pass, there is pass-import, an extension to pass. Since it doesn't deal with firefox's native CSV export anymore though, here's a simple script to do the conversion:

convert_logins.sh
#!/bin/bash
 
logins="$1"
[[ -f $logins ]] || {
	echo "Usage: $(basename $0) logins.csv"
	exit 1
}
 
declare -A urls
 
n=0
readarray lines <"$1"
for line in "${lines[@]}"; do
	IFS="," read -r -a fields <<< "$line"
 
	# combine fields in case values contained a comma
	idx=0
	url="${fields[$((idx++))]}"
	while [[ $idx -le ${#fields[*]} && ${url: -1:1} != \" ]]; do
		url+=",${fields[$((idx++))]}"
	done
	user="${fields[$((idx++))]}"
	while [[ $idx -le ${#fields[*]} && ${user: -1:1} != \" ]]; do
		user+=",${fields[$((idx++))]}"
	done
	pass="${fields[$((idx++))]}"
	while [[ $idx -le ${#fields[*]} && ${pass: -1:1} != \" ]]; do
		pass+=",${fields[$((idx++))]}"
	done
 
	# sanity check before stripping quotes
	for pos in 0 -1; do
		[[ ${url:$pos:1} == \" ]] || echo -e "\n!!! missing quote in url at $pos\n"
		[[ ${user:$pos:1} == \" ]] || echo -e "\n!!! missing quote in user at $pos\n"
		[[ ${pass:$pos:1} == \" ]] || echo -e "\n!!! missing quote in pass at $pos\n"
	done
 
	# strip quotes
	url="${url:1:-1}"
	user="${user:1:-1}"
	pass="${pass:1:-1}"
 
	# skip irrelevant lines
	case "$url" in
	url|chrome://FirefoxAccounts)
		continue
	esac
 
	url=${url#https://}
	url=${url#http://}
	[[ $url == */* ]] && echo -e "\n!!! URL $url still contains slash\n"
 
	[[ ${urls[$url]} && ${urls[$url]} != $user:$pass ]] && { echo -e "\n!!! duplicate entry for $url -> ${urls[$url]} vs $user:$pass\n"; }
	urls=([$url]="$user:$pass")
 
	echo "$((n++)): $url -> $user:$pass"
	pass insert -e "web/$url${user:+/$user}" <<< "$pass"
done

Vice-versa, there is passff firefox addon to use the logins stored in pass from firefox.

Add custom CA certificates

This is trickier than usual since qutebrowser does not read entries in /etc/ssl/certs. Instead, one has to extend the user's nssdb - the system-wide one in /etc/pki is ignored as well.

To list existing entries:

certutil -d sql:$HOME/.pki/nssdb -L

Add a CA certificate:

certutil -d sql:$HOME/.pki/nssdb -A -i /etc/ssl/certs/ca.crt -n "ca.crt" -t "C,,"
util/qutebrowser.txt · Last modified: 2022/05/18 14:56 by phil