Skip to content

Instantly share code, notes, and snippets.

@pkillnine
Last active December 28, 2017 17:36
Show Gist options
  • Save pkillnine/522bed4cdd9ba3a8df189114024f8ce1 to your computer and use it in GitHub Desktop.
Save pkillnine/522bed4cdd9ba3a8df189114024f8ce1 to your computer and use it in GitHub Desktop.
Qutebrowser config file
# ____ _ ___ _ _ ___
# | _ \| |/ (_) | | / _ \
# | |_) | ' /| | | | ____| (_) |
# | __/| . \| | | | |_____\__, |
# |_| |_|\_\_|_|_| /_/
#
# My Qutebrowser config file :D
#
import re
import subprocess
CMD_SEP = ';;'
SELECT_FIRST_INPUT = 'jseval -q var inputs = document.getElementsByTagName("input"); for(var i = 0; i < inputs.length; i++) { var hidden = false; for(var j = 0; j < inputs[i].attributes.length; j++) { hidden = hidden || inputs[i].attributes[j].value.includes("hidden"); }; if(!hidden) { inputs[i].focus(); break; } }'
def multibind(key :str, commands :list, mode='normal', force=True, extend_default_binding=False):
"""Bind a list of commands to a single key."""
if extend_default_binding:
default_binding = c.bindings.default[mode].get(key)
if not default_binding:
raise Exception('Cannot extend default binding: No default key set for {} in {} mode'.format(key, mode))
default_commands = re.split(' *{} *'.format(CMD_SEP), default_binding)
commands = default_commands + commands
command_sequence = ' {} '.format(CMD_SEP).join(commands)
config.bind(key, command_sequence, mode=mode, force=force)
def read_xresources(prefix):
props = {}
x = subprocess.run(['xrdb', '-query'], stdout=subprocess.PIPE)
lines = x.stdout.decode().split('\n')
for line in filter(lambda l : l.startswith(prefix), lines):
prop, _, value = line.partition(':\t')
props[prop] = value
return props
# === GENERAL SETTINGS ===
c.downloads.position = 'bottom'
c.backend = 'webengine'
c.completion.height = '15%'
c.hints.auto_follow_timeout = 1000
c.hints.mode = 'number'
c.messages.timeout = 5000
c.scrolling.bar = True
c.statusbar.position = 'bottom'
c.tabs.position = 'bottom'
c.aliases['set'] = 'set -t'
# === ESCAPE BINDINGS ===
c.aliases['Unfocus'] = 'jseval -q document.activeElement.blur()'
c.aliases['Deselect-text'] = 'jseval -q window.getSelection().removeAllRanges()'
c.aliases['Configure'] = 'spawn -d urxvt -e bash -c "vim ~/.config/qutebrowser/config.py"'
UNFOCUS = 'jseval -q window.getSelection().removeAllRanges()'
DESELECT = 'jseval -q document.activeElement.blur()'
UNHOVER = 'unhover'
CLEAR_ALL = ['clear-messages', UNFOCUS, DESELECT, UNHOVER]
multibind(key='<Escape>', commands=['fake-key <Escape>'] + CLEAR_ALL, mode='normal', extend_default_binding=True)
multibind(key='<Escape>', commands=['clear-messages'], mode='insert', extend_default_binding=True)
multibind(key='<Escape>', commands=['clear-messages'], mode='command', extend_default_binding=True)
multibind(key='<Ctrl-V>', commands=[UNFOCUS, UNHOVER], mode='passthrough', extend_default_binding=True)
# === Other BINDINGs ===
#config.bind('<ctrl-e>', 'spawn -u command-run', mode='command')
config.bind(';i', 'hint images run open {hint-url}', mode='normal', force=True)
config.bind(';I', 'hint images run open -t {hint-url}', mode='normal', force=True)
config.bind('<Return>', 'fake-key <Return>', mode='insert') # Make <ctrl-j> work in insert mode.
config.unbind('d')
c.tabs.select_on_remove = 'last-used'
multibind('<Return>', ['fake-key <Return>'], extend_default_binding=True)
config.bind('gi', 'hint inputs')
c.aliases['Run-in-shell'] = 'spawn -u run-in-shell'
config.bind('!', 'set-cmd-text -s :Run-in-shell')
# === CUSTOM BINDS ===
CUSTOM_BINDS = {
'q' : 'spawn -u quote-website /media/veracrypt1/ghuisdhgisahgbdafgdadajbgdagbhghahguiehuighasjgvscavjklsagnsajklfgnjklsahgksahgahdlghaldfel',
'd' : 'spawn -u download_to_mp3player',
'r' : 'spawn -u readability',
't' : 'spawn -u tmp-session',
'T' : 'spawn -u tmp-session ~/packages/repos/qutebrowser-dev/qutebrowser.py --backend webengine',
'g' : 'spawn -u git-clone',
'm' : 'spawn xdotool mousemove 1440 900',
'xx' : 'hint --add-history links spawn --detach --verbose mpv --force-window=yes --keep-open=yes --loop-file {hint-url}',
'xa' : 'hint --add-history links spawn --detach --verbose mpv --force-window=yes --keep-open=yes --loop-file {hint-url} --ytdl-format=bestaudio',
#'c' : 'spawn -d urxvt -e bash -c "vim ~/.config/qutebrowser/config.py"',
'c' : 'Configure',
}
for k in CUSTOM_BINDS.keys(): config.bind("," + k, CUSTOM_BINDS.get(k))
# === COLOURS ===
xresources = read_xresources('*')
c.colors.statusbar.normal.bg = xresources['*background']
c.colors.messages.warning.fg = 'black'
c.colors.messages.error.bg = 'darkred'
# Default colours
c.colors.statusbar.command.bg = c.colors.statusbar.normal.bg
# === TAB MANAGEMENT ===
#for t in range(9): config.bind('<ctrl-alt-{}>'.format(t), 'run-with-count {} tab-close'.format(t))
for t, k in enumerate(list('!@#$%^&*(')): config.bind('<alt-shift-{}>'.format(k), 'run-with-count {} tab-move'.format(t + 1))
#reason for above line:
#18:12 <pkill9> qutebrowser takes binds to <alt-shift-1> and shows it with the bind command, but it won't recognise it when i press it
#18:14 <The-Compiler> pkill9: looks like you need to bind whatever shift-1 does instead of 1
#18:23 <pkill9> oh like <alt-!>?
#18:24 <The-Compiler> <alt-shift-!> for whatever reason
#18:26 <pkill9> ah that works
# === FONTS ===
settinglist = [
'monospace',
'completion.entry',
'completion.category',
'debug_console',
'downloads',
'keyhint',
'messages.error',
'messages.info',
'messages.warning',
'prompts',
'statusbar',
'tabs',
]
def setfont(item, font, size=10):
setting = 'fonts.{}'.format(item)
font = '{}pt {}'.format(size, font)
config.set(setting, font)
mainfont= 'Roboto Condensed'
c.fonts.monospace = "Fira Mono"
c.fonts.completion.entry = "10pt Fira Mono"
c.fonts.completion.category = "bold 10pt Fira Mono"
c.fonts.debug_console = "10pt Fira Mono"
c.fonts.downloads = "10pt Fira Mono"
c.fonts.hints = "bold 13px Fira Mono"
c.fonts.keyhint = "10pt Fira Mono"
c.fonts.messages.error = "10pt Fira Mono"
c.fonts.messages.info = "10pt Fira Mono"
c.fonts.messages.warning = "10pt Fira Mono"
c.fonts.prompts = "10pt Fira Sans"
c.fonts.statusbar = "10pt Fira Mono"
c.fonts.tabs = "10pt Fira Mono"
c.fonts.web.family.fixed = "Fira Mono"
c.fonts.web.family.sans_serif = "Fira Sans"
c.fonts.web.family.serif = "DejaVu Serif"
for setting in settinglist:
setfont(setting, mainfont, size=10)
c.fonts.web.family.fixed = mainfont
c.fonts.web.family.sans_serif = mainfont
c.fonts.web.family.serif = mainfont
# === READLINE INSERT MODE BINDINGS ===
config.bind('<ctrl-h>', 'fake-key <backspace>', mode='insert')
config.bind('<ctrl-f>', 'fake-key <right>', mode='insert')
config.bind('<ctrl-b>', 'fake-key <left>', mode='insert')
# === HOSTS LISTS ===
c.content.host_blocking.lists.append('https://ssl.bblck.me/blacklists/domain-list.txt')
# dev test
#config.bind(',z', 'message-info bound')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment