1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
|
"""Qutebrowser configuration"""
import os
import re
import sys
import json
import subprocess
import random
from qutebrowser.config.configfiles import ConfigAPI
from qutebrowser.config.config import ConfigContainer
config = config
c = c
leader = '\\'
localleader = ' '
config.load_autoconfig()
# Helper Functions {{{
def toggle_stylesheets(stylesheets):
# TODO: Remove the given stylesheets from the list
return 'config-cycle --temp content.user_stylesheets \'' \
+ json.dumps(c.content.user_stylesheets) \
+ '\' \'' \
+ json.dumps(c.content.user_stylesheets + stylesheets) \
+ '\''
def bind(key, command, mode): # noqa: E302
"""Bind key to command in mode."""
config.bind(key, command, mode=mode)
def nmap(key, command):
"""Bind key to command in normal mode."""
bind(key, command, 'normal')
def imap(key, command):
"""Bind key to command in insert mode."""
bind(key, command, 'insert')
def cmap(key, command):
"""Bind key to command in command mode."""
bind(key, command, 'command')
def tmap(key, command):
"""Bind key to command in caret mode."""
bind(key, command, 'caret')
def pmap(key, command):
"""Bind key to command in passthrough mode."""
bind(key, command, 'passthrough')
def unmap(key, mode):
"""Unbind key in mode."""
config.unbind(key, mode=mode)
def nunmap(key):
"""Unbind key in normal mode."""
unmap(key, mode='normal')
# }}}
#### Config ####
#### Settings {{{
c.backend = "webengine"
c.auto_save.session = True
c.session.lazy_restore = True
c.content.autoplay = True
c.url.open_base_url = True
c.scrolling.bar = 'always'
c.tabs.mousewheel_switching = False
c.scrolling.smooth = True
c.keyhint.delay = 250
c.input.partial_timeout = 0
c.input.spatial_navigation = False
c.content.dns_prefetch = True # Use dns prefetching for speed
c.qt.workarounds.remove_service_workers = True # TODO: Added because of crashes
c.content.pdfjs = True
# Editor
c.editor.command = ['sensible-terminal', '-e', 'sensible-editor', '{}']
c.input.insert_mode.auto_enter = True
c.input.insert_mode.auto_leave = True
c.input.insert_mode.auto_load = True
c.input.insert_mode.leave_on_load = True
# File selector
lf_file_picker = ['sensible-terminal', '-c', 'lf-selector', '-g', '170x40+50+50', '-e', 'lf', '-selection-path', '{}']
c.fileselect.handler = 'external'
c.fileselect.single_file.command = lf_file_picker
c.fileselect.multiple_files.command = lf_file_picker
c.fileselect.folder.command = lf_file_picker
# Hints
c.hints.auto_follow = 'always'
c.hints.chars = 'asdfhjklqwpei1290'
c.hints.auto_follow = 'unique-match'
c.hints.mode = 'number' # number | letter
nunmap('m')
nunmap('M')
nunmap("<Ctrl-a>")
nunmap('<Ctrl-v>')
nunmap('<Ctrl-x>')
nunmap('<Ctrl-V>')
nunmap('<Ctrl-X>')
nunmap('<Ctrl-h>')
nunmap('<Ctrl-p>')
# Edit text and edit url
imap('<Ctrl-e>', 'edit-text')
nmap('<Ctrl-e>', 'edit-text')
nmap(localleader+'e', 'edit-url')
# Pass through actions
nmap('<Ctrl-p>', 'mode-enter passthrough')
pmap('<Ctrl-j>', 'tab-next')
pmap('<Ctrl-k>', 'tab-prev')
# pmap('<Shift-Escape>', 'enter-mode normal') # Default
nunmap("+")
nunmap("-")
nunmap("=")
nmap("z=", "zoom-in")
nmap("z-", "zoom-out")
nmap("zz", "zoom")
# Add search
nmap('n', 'search-next')
nmap('N', 'search-prev')
# Clipboard play
nmap('yy', 'yank selection') # Copy selected text
nmap('yu', 'yank') # Copy url
nmap('yl', 'hint links userscript yank') # Copy a link from page as hints
# Add magnet link to download
c.hints.selectors['torrents'] = [ 'a[href^="magnet:"]' ]
c.aliases['find-torrent-magnet-links'] = 'hint torrents userscript torrent'
nmap(leader + 'td', 'find-torrent-magnet-links')
nmap('<Shift-j>', 'scroll-page 0 0.5')
nmap('<Shift-k>', 'scroll-page 0 -0.5')
# }}}
#### Theme {{{
config.source('ui.py')
## Webpage styles
c.content.user_stylesheets = [
'styles/scrollbar.css',
'styles/default.css',
'styles/adblocker.css',
# TODO: Add user styles for lite.duckduckgo.com. Had issue with CSP
# 'styles/duckduckgo.css'
]
# Dark mode
# c.aliases['toggle-darkmode'] = toggle_stylesheets(['styles/dark.css'])
c.aliases['toggle-darkmode'] = 'config-cycle --temp colors.webpage.darkmode.enabled'
nmap(localleader + 'td', ':toggle-darkmode')
# }}}
#### Sessions {{{
nmap(leader + 'sl', ':cmd-set-text -s :session-load ');
nmap(leader + 'sw', ':cmd-set-text -s :session-save');
# }}}
#### Navigation {{{
# Highlight inputs
nmap('gi', 'hint inputs --mode letter')
nmap('<Ctrl-f>', 'hint --mode=number --rapid links tab-bg')
# Increment pagination
nmap(localleader + 'nn', 'navigate increment')
nmap(localleader + 'nN', 'navigate decrement')
# From clipboard
nmap('p', 'open --tab -- {clipboard}') # Open link in keyboard in a new tab
nmap('P', 'open -- {clipboard}') # Open link in clipboard in the same tab
# }}}
#### TABS {{{
c.tabs.show = 'multiple'
c.tabs.title.format = '{perc}{private} {audio}{index}: {host} - {current_title}'
c.tabs.title.format_pinned = '{index}'
c.tabs.tooltips = True
c.tabs.background = True
c.tabs.select_on_remove = 'next'
c.tabs.new_position.unrelated = 'next'
c.tabs.last_close = 'close' # 'close' for closing window on last d
# Keybindings
nmap('o', 'cmd-set-text -s :open --tab')
nmap('O', 'cmd-set-text -s :open')
# Tab
nmap('d', 'tab-close')
nmap('tt', 'open --tab') # New tab
nmap('tp', 'open -p') # Private window
# Detach tab
nmap(leader + 'wt', 'tab-give')
nmap(leader + 'wp', 'tab-pin')
# Tab movement
nmap('<Ctrl-k>', 'tab-prev')
nmap('<Ctrl-j>', 'tab-next')
nmap('<Ctrl-Tab>', 'tab-next')
nmap('<Ctrl-Shift-Tab>', 'tab-prev')
nmap(localleader + '<Tab>', 'tab-focus last')
nmap('<Ctrl-Shift-k>', 'tab-move -')
nmap('<Ctrl-Shift-j>', 'tab-move +')
nmap(localleader + 'b', 'cmd-set-text -s :tab-select') # List buffers by index
for i in range(1, 10 + 1):
key = 0 if i == 10 else i
nmap(localleader + str(key), 'tab-focus ' + str(i))
# }}}
#### Downloads {{{
c.downloads.location.directory = '~/Downloads/qute'
c.downloads.location.prompt = False
c.downloads.open_dispatcher = 'dl_move {}'
c.downloads.position = 'bottom'
c.downloads.remove_finished = 1000
c.downloads.open_dispatcher = '~/.bin/open'
# c.qt.force_platformtheme='gtk3'
# Goto downloads directory
nunmap('gd')
nmap('gdl', 'spawn --userscript open_downloads')
# Playing Videos with MPV
nmap(leader + 'tyy', 'spawn --detach bash -c "notify-send \\"Loading mpv\\" && mpv --force-window=immediate \\"{url}\\""')
# Download music from youtube
nmap(leader + 'tym', 'spawn --userscript dl_music')
# }}}
#### Security {{{
config.source('security.py')
nmap(leader + 'pp', 'incognito-enable')
nmap(leader + 'pc', 'change-identity')
nmap(leader + 'pd', 'incognito-disable')
# }}}
#### Perdomain permission config {{{
# Notifications
c.content.notifications.presenter = 'libnotify'
c.content.notifications.enabled = 'ask'
c.content.desktop_capture = 'ask'
# Disable
config.set('content.notifications.enabled', False, '*://reddit.com')
config.set('content.notifications.enabled', False, '*://www.reddit.com')
# general
config.set('content.notifications.enabled', True, '*://web.whatsapp.com')
config.set('content.notifications.enabled', True, '*://*.basecamp.com')
config.set('content.notifications.enabled', True, '*://app.slack.com')
# google
config.set('content.notifications.enabled', True, '*://mail.google.com')
config.set('content.notifications.enabled', True, '*://chat.google.com')
config.set('content.notifications.enabled', True, '*://calendar.google.com')
config.set('content.register_protocol_handler', True, '*://calendar.google.com')
config.set('content.notifications.enabled', True, '*://meet.google.com')
# Media
config.set('content.media.audio_video_capture', True, '*://meet.google.com')
config.set('content.media.audio_capture', True, '*://meet.google.com')
config.set('content.media.video_capture', True, '*://meet.google.com')
# }}}
#### Search and bookmarks {{{
# Default start page
c.url.default_page = '~/.config/qutebrowser/homepage/index.html'
c.url.start_pages = [c.url.default_page]
DEFAULT_SEARCH_ENGINE = 'd'
c.url.searchengines = {
# Main general
'ss': 'https://www.startpage.com/do/search?q={}',
'd': 'https://lite.duckduckgo.com/lite?q={}',
'gg': 'https://lite.duckduckgo.com/lite?q={}',
'go': 'https://google.com/search?q={}',
'ai': 'https://chatgpt.com/?temporary-chat=true&q={}',
'aic': 'https://claude.ai/new?q={}',
'br': 'https://search.brave.com/search?q={}',
# Alt general
'sp': 'https://www.startpage.com/sp/search?q={}',
'sx': 'https://searx.fmac.xyz/?q={}',
'q': 'https://www.qwant.com/search?q={}',
# Dev stuff
'bp': 'https://bundlephobia.com/result?p={}',
'rs': 'https://crates.io/search?q={}',
'ciu': 'https://caniuse.com/#search={}',
'npm': 'https://www.npmjs.com/search?q={}',
'g': 'https://github.com/{}',
'gh': 'http://github.com/search?q={}',
'hg': 'http://www.haskell.org/hoogle/?hoogle={}',
'cname': 'https://www.whatsmydns.net/#CNAME/{}',
'nx': 'https://search.nixos.org/packages?channel=unstable&query={}',
'pio': 'https://registry.platformio.org/search?q={}',
'pub': 'https://pub.dev/packages?q={}',
# Media
'r': 'http://www.reddit.com/r/{}/',
'y': 'http://www.youtube.com/results?search_query={}',
'ly': 'http://genius.com/search?q={}',
# Ignore
'DEFAULT': 'http://this-is-a-placeholder.com?q={}',
}
# Default search engine
c.url.searchengines['DEFAULT'] = c.url.searchengines[DEFAULT_SEARCH_ENGINE]
c.url.searchengines['s'] = c.url.searchengines['DEFAULT']
c.aliases['archive'] = 'open --tab http://web.archive.org/save/{url}'
c.aliases['view-archive'] = 'open --tab http://web.archive.org/web/*/{url}'
c.aliases['view-google-cache'] = 'open --tab http://www.google.com/search?q=cache:{url}'
# c.aliases['xa'] = 'quit --save'
c.aliases['h'] = 'help'
c.aliases['mark-resource'] = 'spawn --userscript bookmark resource'
nmap(localleader + 'tm', 'mark-resource')
# }}}
#### Dev {{{
# 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')
# }}}
#### History {{{
nmap('<Shift-h>', 'back --quiet')
nmap('<Shift-l>', 'forward --quiet')
nmap(leader + 'hh', 'history --tab')
# }}}
|