diff options
| author | Yuval Adam <_@yuv.al> | 2016-12-22 23:38:36 +0200 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2016-12-22 23:38:36 +0200 |
| commit | cd276e71e7dd83e38b7a98dc6c5b05d7e9f9dc57 (patch) | |
| tree | db716a7ea02b33cbcc4d6abcebb35bd01c7e8f86 | |
| parent | 530cb133611cb97e21bc616c49a77aac120dc65d (diff) | |
Remove luakit and mutt files for now
| -rw-r--r-- | .config/luakit/adblock.lua | 563 | ||||
| -rw-r--r-- | .config/luakit/adblock_chrome.lua | 204 | ||||
| -rw-r--r-- | .config/luakit/binds.lua | 588 | ||||
| -rw-r--r-- | .config/luakit/globals.lua | 87 | ||||
| -rw-r--r-- | .config/luakit/modes.lua | 163 | ||||
| -rw-r--r-- | .config/luakit/rc.lua | 184 | ||||
| -rw-r--r-- | .config/luakit/theme.lua | 69 | ||||
| -rw-r--r-- | .config/luakit/webview.lua | 350 | ||||
| -rw-r--r-- | .config/luakit/window.lua | 859 | ||||
| -rw-r--r-- | .muttrc | 49 |
10 files changed, 0 insertions, 3116 deletions
diff --git a/.config/luakit/adblock.lua b/.config/luakit/adblock.lua deleted file mode 100644 index 6f5ca17..0000000 --- a/.config/luakit/adblock.lua +++ /dev/null @@ -1,563 +0,0 @@ ------------------------------------------------------------------------- --- Simple URI-based content filter v0.3.1a -- --- (C) 2010 Chris van Dijk (quigybo) <quigybo@hotmail.com> -- --- (C) 2010 Mason Larobina (mason-l) <mason.larobina@gmail.com> -- --- © 2012 Plaque FCC <Reslayer@ya.ru> -- --- © 2010 adblock chromepage from bookmarks.lua by Henning Hasemann & -- --- Mason Larobina taken by Plaque FCC. -- --- -- --- Download an Adblock Plus compatible filter lists to luakit data -- --- dir into "/adblock/" directory for multiple lists support or into -- --- data dir root to use single file. EasyList is the most popular -- --- Adblock Plus filter list: http://easylist.adblockplus.org/ -- --- Filterlists need to be updated regularly (~weekly), use cron! -- ------------------------------------------------------------------------- - -local info = info -local pairs = pairs -local ipairs = ipairs -local assert = assert -local unpack = unpack -local type = type -local io = io -local os = os -local string = string -local table = table -local tostring = tostring -local tonumber = tonumber -local webview = webview -local lousy = require("lousy") -local util = lousy.util -local chrome = require("chrome") -local capi = { luakit = luakit } -local add_binds, add_cmds = add_binds, add_cmds -local lfs = require("lfs") -local window = window - - -module("adblock") - ---- Module global variables -local enabled = true --- Adblock Plus compatible filter lists -local adblock_dir = capi.luakit.data_dir .. "/adblock/" - -local filterfiles = {} -local simple_mode = false -local subscriptions_file = adblock_dir .. "/subscriptions" -subscriptions = {} - - - --- String patterns to filter URI's with -rules = {} - --- Functions to filter URI's by --- Return true or false to allow or block respectively, nil to continue matching -local filterfuncs = {} - --- Fitting for adblock.chrome.refresh_views() -refresh_views = function() - -- Dummy. -end - --- Enable or disable filtering -enable = function () - enabled = true - refresh_views() -end -disable = function () - enabled = false - refresh_views() -end - --- Report AdBlock state: «Enabled» or «Disabled» -state = function() - if enabled then - return "Enabled" - else - return "Disabled" - end -end - -mode = function() - if simple_mode then - return "simple" - else - return "normal" - end -end - --- Detect files to read rules from -function detect_files() - local curdir = lfs.currentdir() - -- Try to find subscriptions directory: - if not lfs.chdir(adblock_dir) then - lfs.mkdir(adblock_dir) - else - simple_mode = false - -- Look for filters lists: - lfs.chdir(curdir) - for filename in lfs.dir(adblock_dir) do - if string.find(filename, ".txt$") then - info("adblock: Found adblock list: " .. filename) - table.insert(filterfiles, filename) - end - end - end - - if table.maxn(filterfiles) < 1 then - simple_mode = true - filterfiles = { "/easylist.txt" } - end - - if not simple_mode then - info( "adblock: Found " .. table.maxn(filterfiles) .. " rules lists.\n" ) - end - - return -end - -local function get_abp_opts(s) - local opts = {} - local pos = string.find(s, "%$") - if pos then - local op = string.sub(s, pos+1) - s = string.sub(s, 1, pos-1) - for key in string.gmatch(op, "[^,]+") do - local val - local pos = string.find(key, "=") - if pos then - val = string.sub(key, pos+1) - key = string.sub(key, 1, pos-1) - end - - local negative = false - if string.sub(key, 1, 1) == "~" then - negative = true - key = string.sub(key, 2) - end - - if key == "domain" and val then - local domains = {} - for v in string.gmatch(val, "[^|]+") do - table.insert(domains, v) - end - if #domains > 0 then opts["domain"] = domains end - elseif key == "third-party" then - opts["third-party"] = not negative - else - opts["unknown"] = true - end - end - end - return s, opts -end - --- Convert Adblock Plus filter description to lua string pattern --- See http://adblockplus.org/en/filters for more information -abp_to_pattern = function (s) - -- Strip filter options - local opts - s, opts = get_abp_opts(s) - if opts and opts.unknown == true then return nil end -- Skip rules with unknown options - - if string.len(s) > 0 then - -- Protect magic characters (^$()%.[]*+-?) not used by ABP (^$()[]*) - s = string.gsub(s, "([%%%.%+%-%?])", "%%%1") - - -- Wildcards are globbing - s = string.gsub(s, "%*", "%.%*") - - -- Caret is separator (anything but a letter, a digit, or one of the following:Â - . %) - s = string.gsub(s, "%^", "[^%%w%%-%%.%%%%]") - - -- Double pipe is domain anchor (beginning only) - -- Unfortunately "||example.com" will also match "wexample.com" (lua doesn't do grouping) - s = string.gsub(s, "^||", "^https?://[^/]*%%.?") - - -- Pipe is anchor - s = string.gsub(s, "^|", "%^") - s = string.gsub(s, "|$", "%$") - - -- Convert to lowercase ($match-case option is not honoured) - s = string.lower(s) - end - - return s, opts -end - -add_unique_cached = function (pattern, opts, tab, cache_tab) - if cache_tab[pattern] then - return false - else - --cache_tab[pattern], tab[pattern] = true, pattern - cache_tab[pattern], tab[pattern] = true, opts - return true - end -end - --- Parses an Adblock Plus compatible filter list -parse_abpfilterlist = function (filename, cache) - if os.exists(filename) then - info("adblock: loading filterlist %s", filename) - else - info("adblock: error loading filter list (%s: No such file or directory)", filename) - end - --*** - --local f = io.open(filename .. "~", "w") - --*** - local pat, opts - local white, black, wlen, blen, icnt = {}, {}, 0, 0, 0 - for line in io.lines(filename) do - -- Ignore comments, header and blank lines - if line:match("^[![]") or line:match("^$") then - -- dammitwhydoesntluahaveacontinuestatement - - -- Ignore element hiding - elseif line:match("#") then - --icnt = icnt + 1 - - -- Check for exceptions (whitelist) - elseif line:match("^@@") then - pat, opts = abp_to_pattern(string.sub(line, 3)) - if pat and pat ~= "^http://" then - if add_unique_cached(pat, opts, white, cache.white) then - wlen = wlen + 1 - --*** - --f:write("W " .. pat .. "\n") - --*** - else - icnt = icnt + 1 - end - -- table.insert(white, pat) - else - icnt = icnt + 1 - end - - -- Add everything else to blacklist - else - pat, opts = abp_to_pattern(line) - if pat and pat ~= "^http:" and pat ~= ".*" then - if add_unique_cached(pat, opts, black, cache.black) then - blen = blen + 1 - --*** - --f:write("B " .. pat .. "\n") - --*** - else - icnt = icnt + 1 - end - -- table.insert(black, pat) - else - icnt = icnt + 1 - end - end - end - --*** - --f:close() - --*** - - return white, black, wlen, blen, icnt -end - --- Load filter list files -load = function (reload, single_list) - if reload then subscriptions, filterfiles = {}, {} end - detect_files() - if not simple_mode and not single_list then - read_subscriptions() - local files_list = {} - for _, filename in ipairs(filterfiles) do - local list = subscriptions[filename] - if list and util.table.hasitem(list.opts, "Enabled") then - table.insert(files_list, filename) - else - add_list("", filename, "Disabled", true, false) - end - end - filterfiles = files_list - -- Yes we may have changed subscriptions and even fixed something with them. - write_subscriptions() - end - - -- [re-]loading: - if reload then rules = {} end - local filters_dir = adblock_dir - if simple_mode then - filters_dir = capi.luakit.data_dir - end - local filterfiles_loading = {} - if single_list and not reload then - filterfiles_loading = { single_list } - else - filterfiles_loading = filterfiles - end - local rules_cache = { - black = {}, - white = {} - } -- This cache should let us avoid unnecessary filters duplication. - - for _, filename in ipairs(filterfiles_loading) do - local white, black, wlen, blen, icnt = parse_abpfilterlist(filters_dir .. filename, rules_cache) - local list = {} - if not simple_mode then - list = subscriptions[filename] - else - local list_found = rules[filename] - if list_found then - list = list_found - end - end - if not util.table.hasitem(rules, list) then - rules[filename] = list - end - list.title, list.white, list.black, list.ignored = filename, wlen or 0, blen or 0, icnt or 0 - list.whitelist, list.blacklist = white or {}, black or {} - end - - rules_cache.white, rules_cache.black = nil, nil - rules_cache = nil - refresh_views() -end - -local function domain_match(domain, opts) - local res = false - local cnt = 0 - local dlist = opts["domain"] - if dlist then - for _, s in pairs(dlist) do - if string.len(s) > 0 then - if string.sub(s, 1, 1) == "~" then - if domain == string.sub(s, 2) then return false end - else - cnt = cnt + 1 - if not res and domain == s then res = true end - end - end - end - end - return cnt == 0 or res -end - -local function third_party_match(page_domain, domain2, opts) - local thp = opts["third-party"] - if thp ~= nul then - if thp == true then return domain1 ~= domain2 end - return domain1 == domain2 - end - return true -end - -local function domain_from_uri(uri) - local domain = (uri and string.match(string.lower(uri), "^%a+://([^/]*)/?")) - -- Strip leading www. www2. etc - domain = string.match(domain or "", "^www%d?%.(.+)") or domain - return domain or "" -end - --- Tests URI against user-defined filter functions, then whitelist, then blacklist -match = function (uri, signame, page_uri) - -- Matching is not case sensitive - uri = string.lower(uri) - - signame = signame or "" - - local page_domain, uri_domain - if signame ~= "navigation-request" then - page_domain = domain_from_uri(page_uri) - uri_domain = domain_from_uri(uri) - else - page_domain = domain_from_uri(uri) - uri_domain = page_uri - end - - -- Test uri against filterfuncs - for _, func in ipairs(filterfuncs) do - local ret = func(uri) - if ret ~= nil then - info("adblock: filter function %s returned %s to uri %s", tostring(func), tostring(ret), uri) - return ret - end - end - - -- Test against each list's whitelist rules first - for _, list in pairs(rules) do - -- Check for a match to whitelist - for pattern, opts in pairs(list.whitelist or {}) do - if third_party_match(page_domain, uri_domain, opts) then - if domain_match(page_domain, opts) and string.match(uri, pattern) then - info("adblock: allowing %q as pattern %q matched to uri %s", signame, pattern, uri) - return true - end - end - end - end - - -- Test against each list's blacklist rules - for _, list in pairs(rules) do - -- Check for a match to blacklist - for pattern, opts in pairs(list.blacklist or {}) do - if third_party_match(page_domain, uri_domain, opts) then - if domain_match(page_domain, opts) and string.match(uri, pattern) then - info("adblock: blocking %q as pattern %q matched to uri %s", signame, pattern, uri) - return false - end - end - end - end -end - --- Direct requests to match function -filter = function (v, uri, signame) - if enabled then return match(uri, signame or "", v.uri) end -end - -function table.itemid(t, item) - local pos = 0 - for id, v in pairs(t) do - pos = pos + 1 - if v == item then - return pos - end - end -end - --- Connect signals to all webview widgets on creation -webview.init_funcs.adblock_signals = function (view, w) - --view:add_signal("navigation-request", function (v, uri) return filter(v, uri, "navigation-request") end) - view:add_signal("resource-request-starting", function (v, uri) return filter(v, uri, "resource-request-starting") end) -end - --- Remove options and add new ones to list --- @param list_index Index of the list to modify --- @param opt_ex Options to exclude --- @param opt_inc Options to include -function list_opts_modify(list_index, opt_ex, opt_inc) - assert( simple_mode == false, "adblock list management: not supported in simple mode" ) - assert(type(list_index) == "number", "list options modify: invalid list index") - assert(list_index > 0, "list options modify: index has to be > 0") - if not opt_ex then opt_ex = {} end - if not opt_inc then opt_inc = {} end - - if type(opt_ex) == "string" then opt_ex = util.string.split(opt_ex) end - if type(opt_inc) == "string" then opt_inc = util.string.split(opt_inc) end - - local list = util.table.values(subscriptions)[list_index] - local opts = opt_inc - for _, opt in ipairs(list.opts) do - if not util.table.hasitem(opt_ex, opt) then - table.insert(opts, opt) - end - end - - -- Manage list's rules - local listIDfound = table.itemid(rules, list) - if util.table.hasitem(opt_inc, "Enabled") then - if not listIDfound then - load(false, list.title) - end - elseif util.table.hasitem(opt_inc, "Disabled") then - rules[list.title] = nil - end - - list.opts = opts - write_subscriptions() - refresh_views() -end - ---- Add a list to the in-memory lists table -function add_list(uri, title, opts, replace, save_lists) - assert( (title ~= nil) and (title ~= ""), "adblock list add: no title given") - if not opts then opts = {} end - - -- Create tags table from string - if type(opts) == "string" then opts = util.string.split(opts) end - if table.maxn(opts) == 0 then table.insert(opts, "Disabled") end - if not replace and ( subscriptions[title] or subscriptions[uri] ) then - local list = subscriptions[title] or subscriptions[uri] - -- Merge tags - for _, opts in ipairs(opts) do - if not util.table.hasitem(list, opts) then table.insert(list, opts) end - end - else - -- Insert new adblock list - local list = { uri = uri, title = title, opts = opts } - if not (uri == "" or uri == nil) then - subscriptions[uri] = list - end - if not (title == "" or title == nil) then - subscriptions[title] = list - end - end - - -- Save by default - if save_lists ~= false then write_subscriptions() end -end - ---- Save the in-memory subscriptions to flatfile. --- @param file The destination file or the default location if nil. -function write_subscriptions(file) - if not file then file = subscriptions_file end - - local lines = {} - local added = {} - for _, list in pairs(subscriptions) do - if not util.table.hasitem(added, list) then - local subs = { uri = list.uri, title = list.title, opts = table.concat(list.opts or {}, " "), } - local line = string.gsub("{title}\t{uri}\t{opts}", "{(%w+)}", subs) - table.insert(added, list) - table.insert(lines, line) - end - end - - -- Write table to disk - local fh = io.open(file, "w") - fh:write(table.concat(lines, "\n")) - io.close(fh) -end - ---- Load subscriptions from a flatfile to memory. --- @param file The subscriptions file or the default subscriptions location if nil. --- @param clear_first Should the subscriptions in memory be dumped before loading. -function read_subscriptions(file, clear_first) - if clear_first then clear() end - - -- Find a subscriptions file - if not file then file = subscriptions_file end - if not os.exists(file) then return end - - -- Read lines into subscriptions data table - for line in io.lines(file or subscriptions_file) do - local title, uri, opts = unpack(util.string.split(line, "\t")) - if title ~= "" then add_list(uri, title, opts, false, false) end - end -end - - --- Add commands. -local cmd = lousy.bind.cmd -add_cmds({ - cmd({"adblock-reload", "abr"}, function (w) - info("adblock: Reloading filters.") - load(true) - info("adblock: Reloading filters complete.") - end), - - cmd({"adblock-list-enable", "able"}, function (w, a) - list_opts_modify(tonumber(a), "Disabled", "Enabled") - end), - - cmd({"adblock-list-disable", "abld"}, function (w, a) - list_opts_modify(tonumber(a), "Enabled", "Disabled") - end), - cmd({"adblock-enable", "abe"}, function (w) - enable() - end), - - cmd({"adblock-disable", "abd"}, function (w) - disable() - end), -}) - --- Initialise module -load() diff --git a/.config/luakit/adblock_chrome.lua b/.config/luakit/adblock_chrome.lua deleted file mode 100644 index 1e67006..0000000 --- a/.config/luakit/adblock_chrome.lua +++ /dev/null @@ -1,204 +0,0 @@ -local adblock = require("adblock") -local lousy = lousy -local util = lousy.util -local add_binds, add_cmds = add_binds, add_cmds -local chrome = chrome -local type = type -local tostring = tostring -local tonumber = tonumber -local pairs = pairs -local ipairs = ipairs -local string = string -local table = table -local window = window - - -module("adblock_chrome") - --- Templates -header_template = [==[<div class="header"><h2>AdBlock module: {state}</h2><br>AdBlock is in <b>{mode}</b> mode.{rules}</div><hr>]==] -rules_template = [==[ {black} rules blacklisting, {white} rules whitelisting, {ignored} rules ignored.]==] -block_template = [==[<div class="tag"><h1>{opt}</h1><ul>{links}</ul></div>]==] -list_template_enabled = [==[<li>{title}: <i>(b{black}/w{white}/i{ignored}), </i> <a href="{uri}">{name}</a> <span class="id">{id}</span></li>]==] -list_template_disabled = [==[<li>{title}: <a href="{uri}">{name}</a> <span class="id">{id}</span></li>]==] - -html_template = [==[ -<html> -<head> - <title>{title}</title> - <style type="text/css"> - {style} - </style> -</head> -<body> -{header} -{opts} -</body> -</html> -]==] - --- Template subs -html_page_title = "AdBlock filters" - -html_style = [===[ - body { - font-family: monospace; - margin: 25px; - line-height: 1.5em; - font-size: 12pt; - } - div.tag { - width: 100%; - padding: 0px; - margin: 0 0 25px 0; - clear: both; - } - span.id { - font-size: small; - color: #333333; - float: right; - } - .tag ul { - padding: 0; - margin: 0; - list-style-type: none; - } - .tag h1 { - font-size: 12pt; - font-weight: bold; - font-style: normal; - font-variant: small-caps; - padding: 0 0 5px 0; - margin: 0; - color: #CC3333; - border-bottom: 1px solid #aaa; - } - .tag a:link { - color: #0077bb; - text-decoration: none; - } - .tag a:hover { - color: #0077bb; - text-decoration: underline; - } -]===] - - --- Functions --- Refresh open filters views (if any) -function refresh_views() - for _, w in pairs(window.bywidget) do - for _, v in ipairs(w.tabs.children) do - if string.match(v.uri, "^luakit://adblock/?") then - v:reload() - end - end - end -end - --- Enable adblock to refresh this chrome view. -adblock.refresh_views = refresh_views - --- URI of the chrome page -chrome_page = "luakit://adblock/" - ---- Shows the chrome page in the given view. -chrome.add("adblock", function (view, meta) - local uri = chrome_page - -- Get a list of all the unique tags in all the lists and build a - -- relation between a given tag and a list of subscriptions with that tag. - local opts = {} - local id = 0 - for _, list in pairs(adblock.subscriptions) do - id = id + 1 - list['id'] = id - for _, opt in ipairs(list.opts) do - if not opts[opt] then opts[opt] = {} end - opts[opt][list.title] = list - end - end - - -- For each opt build a block - local lines = {} - for _, opt in ipairs(util.table.keys(opts)) do - local links = {} - for _, title in ipairs(util.table.keys(opts[opt])) do - local list = opts[opt][title] - local link_subs = { - uri = list.uri, - id = list.id, - name = util.escape(list.uri), - title = list.title, - white = list.white, - black = list.black, - ignored = list.ignored - } - local list_template = list_template_disabled - -- Show rules count only when enabled this list and have read its rules - if util.table.hasitem(list.opts, "Enabled") and list.white and list.black and list.ignored then - -- For totals count items only once (protection from multi-tagging by several opts confusion) - list_template = list_template_enabled - end - local link = string.gsub(list_template, "{(%w+)}", link_subs) - table.insert(links, link) - end - - local block_subs = { - opt = opt, - links = table.concat(links, "\n") - } - local block = string.gsub(block_template, "{(%w+)}", block_subs) - table.insert(lines, block) - end - - local rulescount = { black = 0, white = 0, ignored = 0 } - for _, list in pairs(adblock.rules) do - if list.black and list.white and list.ignored then - rulescount.black, rulescount.white, rulescount.ignored = rulescount.black + list.black, rulescount.white + list.white, rulescount.ignored + list.ignored - end - end - -- Display rules count only if have them been count - local html_rules = "" - if rulescount.black + rulescount.white + rulescount.ignored > 0 then - html_rules = string.gsub(rules_template, "{(%w+)}", rulescount) - end - -- Fill the header - local header_subs = { - state = adblock.state(), - mode = adblock.mode(), - rules = html_rules, - } - local html_page_header = string.gsub(header_template, "{(%w+)}", header_subs) - - local html_subs = { - opts = table.concat(lines, "\n\n"), - title = html_page_title, - header = html_page_header, - style = html_style, - } - - local html = string.gsub(html_template, "{(%w+)}", html_subs) - view:load_string(html, tostring(uri)) -end) - --- Add chrome binds. -local key, buf = lousy.bind.key, lousy.bind.buf -add_binds("normal", { - buf("^ga$", function (w) - w:navigate(chrome_page) - end), - - buf("^gA$", function (w, b, m) - for i=1, m.count do - w:new_tab(chrome_page) - end - end, {count=1}), -}) - --- Add chrome commands. -local cmd = lousy.bind.cmd -add_cmds({ - cmd("adblock", function (w) - w:navigate("luakit://adblock/") - end), -}) diff --git a/.config/luakit/binds.lua b/.config/luakit/binds.lua deleted file mode 100644 index 4fc718c..0000000 --- a/.config/luakit/binds.lua +++ /dev/null @@ -1,588 +0,0 @@ ------------------ --- Keybindings -- ------------------ - --- Binding aliases -local key, buf, but = lousy.bind.key, lousy.bind.buf, lousy.bind.but -local cmd, any = lousy.bind.cmd, lousy.bind.any - --- Util aliases -local match, join = string.match, lousy.util.table.join -local strip, split = lousy.util.string.strip, lousy.util.string.split - --- Globals or defaults that are used in binds -local scroll_step = globals.scroll_step or 20 -local zoom_step = globals.zoom_step or 0.1 - --- Add binds to a mode -function add_binds(mode, binds, before) - assert(binds and type(binds) == "table", "invalid binds table type: " .. type(binds)) - mode = type(mode) ~= "table" and {mode} or mode - for _, m in ipairs(mode) do - local mdata = get_mode(m) - if mdata and before then - mdata.binds = join(binds, mdata.binds or {}) - elseif mdata then - mdata.binds = mdata.binds or {} - for _, b in ipairs(binds) do table.insert(mdata.binds, b) end - else - new_mode(m, { binds = binds }) - end - end -end - --- Add commands to command mode -function add_cmds(cmds, before) - add_binds("command", cmds, before) -end - --- Adds the default menu widget bindings to a mode -menu_binds = { - -- Navigate items - key({}, "j", function (w) w.menu:move_down() end), - key({}, "k", function (w) w.menu:move_up() end), - key({}, "Down", function (w) w.menu:move_down() end), - key({}, "Up", function (w) w.menu:move_up() end), - key({}, "Tab", function (w) w.menu:move_down() end), - key({"Shift"}, "Tab", function (w) w.menu:move_up() end), -} - --- Add binds to special mode "all" which adds its binds to all modes. -add_binds("all", { - key({}, "Escape", "Return to `normal` mode.", - function (w) w:set_mode() end), - - key({"Control"}, "[", "Return to `normal` mode.", - function (w) w:set_mode() end), - - -- Mouse bindings - but({}, 8, "Go back.", - function (w) w:back() end), - - but({}, 9, "Go forward.", - function (w) w:forward() end), - - -- Open link in new tab or navigate to selection - but({}, 2, [[Open link under mouse cursor in new tab or navigate to the - contents of `luakit.selection.primary`.]], - function (w, m) - -- Ignore button 2 clicks in form fields - if not m.context.editable then - -- Open hovered uri in new tab - local uri = w.view.hovered_uri - if uri then - w:new_tab(uri, false) - else -- Open selection in current tab - uri = luakit.selection.primary - if uri then w:navigate(w:search_open(uri)) end - end - end - end), - - -- Open link in new tab when Ctrl-clicked. - but({"Control"}, 1, "Open link under mouse cursor in new tab.", - function (w, m) - local uri = w.view.hovered_uri - if uri then - w:new_tab(uri, false) - end - end), - - -- Zoom binds - but({"Control"}, 4, "Increase text zoom level.", - function (w, m) w:zoom_in() end), - - but({"Control"}, 5, "Reduce text zoom level.", - function (w, m) w:zoom_out() end), - - -- Horizontal mouse scroll binds - but({"Shift"}, 4, "Scroll left.", - function (w, m) w:scroll{ xrel = -scroll_step } end), - - but({"Shift"}, 5, "Scroll right.", - function (w, m) w:scroll{ xrel = scroll_step } end), -}) - -add_binds("normal", { - -- Autoparse the `[count]` before a binding and re-call the hit function - -- with the count removed and added to the opts table. - any([[Meta-binding to detect the `^[count]` syntax. The `[count]` is parsed - and stripped from the internal buffer string and the value assigned to - `state.count`. Then `lousy.bind.hit()` is re-called with the modified - buffer string & original modifier state. - - #### Example binding - - lousy.bind.key({}, "%", function (w, state) - w:scroll{ ypct = state.count } - end, { count = 0 }) - - This binding demonstrates several concepts. Firstly that you are able to - specify per-binding default values of `count`. In this case if the user - types `"%"` the document will be scrolled vertically to `0%` (the top). - - If the user types `"100%"` then the document will be scrolled to `100%` - (the bottom). All without the need to use `lousy.bind.buf` bindings - everywhere and or using a `^(%d*)` pattern prefix on every binding which - would like to make use of the `[count]` syntax.]], - function (w, m) - local count, buf - if m.buffer then - count = string.match(m.buffer, "^(%d+)") - end - if count then - buf = string.sub(m.buffer, #count + 1, (m.updated_buf and -2) or -1) - local opts = join(m, {count = tonumber(count)}) - opts.buffer = (#buf > 0 and buf) or nil - if lousy.bind.hit(w, m.binds, m.mods, m.key, opts) then - return true - end - end - return false - end), - - key({}, "i", "Enter `insert` mode.", - function (w) w:set_mode("insert") end), - - key({}, ":", "Enter `command` mode.", - function (w) w:set_mode("command") end), - - -- Scrolling - key({}, "j", "Scroll document down.", - function (w) w:scroll{ yrel = scroll_step } end), - - key({}, "k", "Scroll document up.", - function (w) w:scroll{ yrel = -scroll_step } end), - - key({}, "h", "Scroll document left.", - function (w) w:scroll{ xrel = -scroll_step } end), - - key({}, "l", "Scroll document right.", - function (w) w:scroll{ xrel = scroll_step } end), - - key({}, "Down", "Scroll document down.", - function (w) w:scroll{ yrel = scroll_step } end), - - key({}, "Up", "Scroll document up.", - function (w) w:scroll{ yrel = -scroll_step } end), - - key({}, "Left", "Scroll document left.", - function (w) w:scroll{ xrel = -scroll_step } end), - - key({}, "Right", "Scroll document right.", - function (w) w:scroll{ xrel = scroll_step } end), - - key({}, "^", "Scroll to the absolute left of the document.", - function (w) w:scroll{ x = 0 } end), - - key({}, "$", "Scroll to the absolute right of the document.", - function (w) w:scroll{ x = -1 } end), - - key({}, "0", "Scroll to the absolute left of the document.", - function (w, m) - if not m.count then w:scroll{ y = 0 } else return false end - end), - - key({"Control"}, "e", "Scroll document down.", - function (w) w:scroll{ yrel = scroll_step } end), - - key({"Control"}, "y", "Scroll document up.", - function (w) w:scroll{ yrel = -scroll_step } end), - - key({"Control"}, "d", "Scroll half page down.", - function (w) w:scroll{ ypagerel = 0.5 } end), - - key({"Control"}, "u", "Scroll half page up.", - function (w) w:scroll{ ypagerel = -0.5 } end), - - key({"Control"}, "f", "Scroll page down.", - function (w) w:scroll{ ypagerel = 1.0 } end), - - key({"Control"}, "b", "Scroll page up.", - function (w) w:scroll{ ypagerel = -1.0 } end), - - key({}, "space", "Scroll page down.", - function (w) w:scroll{ ypagerel = 1.0 } end), - - key({"Shift"}, "space", "Scroll page up.", - function (w) w:scroll{ ypagerel = -1.0 } end), - - key({}, "BackSpace", "Scroll page up.", - function (w) w:scroll{ ypagerel = -1.0 } end), - - key({}, "Page_Down", "Scroll page down.", - function (w) w:scroll{ ypagerel = 1.0 } end), - - key({}, "Page_Up", "Scroll page up.", - function (w) w:scroll{ ypagerel = -1.0 } end), - - key({}, "Home", "Go to the end of the document.", - function (w) w:scroll{ y = 0 } end), - - key({}, "End", "Go to the top of the document.", - function (w) w:scroll{ y = -1 } end), - - -- Specific scroll - buf("^gg$", "Go to the top of the document.", - function (w, b, m) w:scroll{ ypct = m.count } end, {count=0}), - - buf("^G$", "Go to the bottom of the document.", - function (w, b, m) w:scroll{ ypct = m.count } end, {count=100}), - - buf("^%%$", "Go to `[count]` percent of the document.", - function (w, b, m) w:scroll{ ypct = m.count } end), - - -- Zooming - key({}, "+", "Enlarge text zoom of the current page.", - function (w, m) w:zoom_in(zoom_step * m.count) end, {count=1}), - - key({}, "-", "Reduce text zom of the current page.", - function (w, m) w:zoom_out(zoom_step * m.count) end, {count=1}), - - key({}, "=", "Reset zoom level.", - function (w, m) w:zoom_set() end), - - buf("^z[iI]$", [[Enlarge text zoom of current page with `zi` or `zI` to - reduce full zoom.]], - function (w, b, m) - w:zoom_in(zoom_step * m.count, b == "zI") - end, {count=1}), - - buf("^z[oO]$", [[Reduce text zoom of current page with `zo` or `zO` to - reduce full zoom.]], - function (w, b, m) - w:zoom_out(zoom_step * m.count, b == "zO") - end, {count=1}), - - -- Zoom reset or specific zoom ([count]zZ for full content zoom) - buf("^z[zZ]$", [[Set current page zoom to `[count]` percent with - `[count]zz`, use `[count]zZ` to set full zoom percent.]], - function (w, b, m) - w:zoom_set(m.count/100, b == "zZ") - end, {count=100}), - - -- Fullscreen - key({}, "F11", "Toggle fullscreen mode.", - function (w) w.win.fullscreen = not w.win.fullscreen end), - - -- Clipboard - key({}, "p", [[Open a URL based on the current primary selection contents - in the current tab.]], - function (w) - local uri = luakit.selection.primary - if not uri then w:notify("No primary selection...") return end - w:navigate(w:search_open(uri)) - end), - - key({}, "P", [[Open a URL based on the current primary selection contents - in `[count=1]` new tab(s).]], - function (w, m) - local uri = luakit.selection.primary - if not uri then w:notify("No primary selection...") return end - for i = 1, m.count do w:new_tab(w:search_open(uri)) end - end, {count = 1}), - - -- Yanking - key({}, "y", "Yank current URI to primary selection.", - function (w) - local uri = string.gsub(w.view.uri or "", " ", "%%20") - luakit.selection.primary = uri - w:notify("Yanked uri: " .. uri) - end), - - -- Commands - key({"Control"}, "a", "Increment last number in URL.", - function (w) w:navigate(w:inc_uri(1)) end), - - key({"Control"}, "x", "Decrement last number in URL.", - function (w) w:navigate(w:inc_uri(-1)) end), - - key({}, "o", "Open one or more URLs.", - function (w) w:enter_cmd(":open ") end), - - key({}, "t", "Open one or more URLs in a new tab.", - function (w) w:enter_cmd(":tabopen ") end), - - key({}, "w", "Open one or more URLs in a new window.", - function (w) w:enter_cmd(":winopen ") end), - - key({}, "O", "Open one or more URLs based on current location.", - function (w) w:enter_cmd(":open " .. (w.view.uri or "")) end), - - key({}, "T", - "Open one or more URLs based on current location in a new tab.", - function (w) w:enter_cmd(":tabopen " .. (w.view.uri or "")) end), - - key({}, "W", - "Open one or more URLs based on current locaton in a new window.", - function (w) w:enter_cmd(":winopen " .. (w.view.uri or "")) end), - - -- History - key({}, "H", "Go back in the browser history `[count=1]` items.", - function (w, m) w:back(m.count) end), - - key({}, "L", "Go forward in the browser history `[count=1]` times.", - function (w, m) w:forward(m.count) end), - - key({}, "XF86Back", "Go back in the browser history.", - function (w, m) w:back(m.count) end), - - key({}, "XF86Forward", "Go forward in the browser history.", - function (w, m) w:forward(m.count) end), - - key({"Control"}, "o", "Go back in the browser history.", - function (w, m) w:back(m.count) end), - - key({"Control"}, "i", "Go forward in the browser history.", - function (w, m) w:forward(m.count) end), - - -- Tab - key({"Control"}, "Page_Up", "Go to previous tab.", - function (w) w:prev_tab() end), - - key({"Control"}, "Page_Down", "Go to next tab.", - function (w) w:next_tab() end), - - key({"Control"}, "Tab", "Go to next tab.", - function (w) w:next_tab() end), - - key({"Shift","Control"}, "Tab", "Go to previous tab.", - function (w) w:prev_tab() end), - - buf("^gT$", "Go to previous tab.", - function (w) w:prev_tab() end), - - buf("^gt$", "Go to next tab (or `[count]` nth tab).", - function (w, b, m) - if not w:goto_tab(m.count) then w:next_tab() end - end, {count=0}), - - buf("^g0$", "Go to first tab.", - function (w) w:goto_tab(1) end), - - buf("^g$$", "Go to last tab.", - function (w) w:goto_tab(-1) end), - - key({"Control"}, "t", "Open a new tab.", - function (w) w:new_tab(globals.homepage) end), - - key({"Control"}, "w", "Close current tab.", - function (w) w:close_tab() end), - - key({}, "d", "Close current tab (or `[count]` tabs).", - function (w, m) for i=1,m.count do w:close_tab() end end, {count=1}), - - key({}, "<", "Reorder tab left `[count=1]` positions.", - function (w, m) - w.tabs:reorder(w.view, w.tabs:current() - m.count) - end, {count=1}), - - key({}, ">", "Reorder tab right `[count=1]` positions.", - function (w, m) - w.tabs:reorder(w.view, - (w.tabs:current() + m.count) % w.tabs:count()) - end, {count=1}), - - buf("^gH$", "Open homepage in new tab.", - function (w) w:new_tab(globals.homepage) end), - - buf("^gh$", "Open homepage.", - function (w) w:navigate(globals.homepage) end), - - buf("^gy$", "Duplicate current tab.", - function (w) w:new_tab(w.view.history or "") end), - - key({}, "r", "Reload current tab.", - function (w) w:reload() end), - - key({}, "R", "Reload current tab (skipping cache).", - function (w) w:reload(true) end), - - key({"Control"}, "c", "Stop loading the current tab.", - function (w) w.view:stop() end), - - key({"Control", "Shift"}, "R", "Restart luakit (reloading configs).", - function (w) w:restart() end), - - -- Window - buf("^ZZ$", "Quit and save the session.", - function (w) w:save_session() w:close_win() end), - - buf("^ZQ$", "Quit and don't save the session.", - function (w) w:close_win() end), - - buf("^D$", "Quit and don't save the session.", - function (w) w:close_win() end), - - -- Enter passthrough mode - key({"Control"}, "z", - "Enter `passthrough` mode, ignores all luakit keybindings.", - function (w) w:set_mode("passthrough") end), -}) - -add_binds("insert", { - key({"Control"}, "z", - "Enter `passthrough` mode, ignores all luakit keybindings.", - function (w) w:set_mode("passthrough") end), -}) - -readline_bindings = { - key({"Shift"}, "Insert", - "Insert contents of primary selection at cursor position.", - function (w) w:insert_cmd(luakit.selection.primary) end), - - key({"Control"}, "w", "Delete previous word.", - function (w) w:del_word() end), - - key({"Control"}, "u", "Delete until beginning of current line.", - function (w) w:del_line() end), - - key({"Control"}, "h", "Delete character to the left.", - function (w) w:del_backward_char() end), - - key({"Control"}, "d", "Delete character to the right.", - function (w) w:del_forward_char() end), - - key({"Control"}, "a", "Move cursor to beginning of current line.", - function (w) w:beg_line() end), - - key({"Control"}, "e", "Move cursor to end of current line.", - function (w) w:end_line() end), - - key({"Control"}, "f", "Move cursor forward one character.", - function (w) w:forward_char() end), - - key({"Control"}, "b", "Move cursor backward one character.", - function (w) w:backward_char() end), - - key({"Mod1"}, "f", "Move cursor forward one word.", - function (w) w:forward_word() end), - - key({"Mod1"}, "b", "Move cursor backward one word.", - function (w) w:backward_word() end), -} - -add_binds({"command", "search"}, readline_bindings) - --- Switching tabs with Mod1+{1,2,3,...} -mod1binds = {} -for i=1,10 do - table.insert(mod1binds, - key({"Mod1"}, tostring(i % 10), "Jump to tab at index "..i..".", - function (w) w.tabs:switch(i) end)) -end -add_binds("normal", mod1binds) - --- Command bindings which are matched in the "command" mode from text --- entered into the input bar. -add_cmds({ - buf("^%S+!", - [[Detect bang syntax in `:command!` and recursively calls - `lousy.bind.match_cmd(..)` removing the bang from the command string - and setting `bang = true` in the bind opts table.]], - function (w, cmd, opts) - local cmd, args = string.match(cmd, "^(%S+)!+(.*)") - if cmd then - opts = join(opts, { bang = true }) - return lousy.bind.match_cmd(w, opts.binds, cmd .. args, opts) - end - end), - - cmd("c[lose]", "Close current tab.", - function (w) w:close_tab() end), - - cmd("print", "Print current page.", - function (w) w.view:eval_js("print()") end), - - cmd("stop", "Stop loading.", - function (w) w.view:stop() end), - - cmd("reload", "Reload page", - function (w) w:reload() end), - - cmd("restart", "Restart browser (reload config files).", - function (w) w:restart() end), - - cmd("write", "Save current session.", - function (w) w:save_session() end), - - cmd("noh[lsearch]", "Clear search highlighting.", - function (w) w:clear_search() end), - - cmd("back", "Go back in the browser history `[count=1]` items.", - function (w, a) w:back(tonumber(a) or 1) end), - - cmd("f[orward]", "Go forward in the browser history `[count=1]` items.", - function (w, a) w:forward(tonumber(a) or 1) end), - - cmd("inc[rease]", "Increment last number in URL.", - function (w, a) w:navigate(w:inc_uri(tonumber(a) or 1)) end), - - cmd("o[pen]", "Open one or more URLs.", - function (w, a) w:navigate(w:search_open(a)) end), - - cmd("t[abopen]", "Open one or more URLs in a new tab.", - function (w, a) w:new_tab(w:search_open(a)) end), - - cmd("w[inopen]", "Open one or more URLs in a new window.", - function (w, a) window.new{w:search_open(a)} end), - - cmd({"javascript", "js"}, "Evaluate JavaScript snippet.", - function (w, a) w.view:eval_js(a) end), - - -- Tab manipulation commands - cmd("tab", "Execute command and open result in new tab.", - function (w, a) w:new_tab() w:run_cmd(":" .. a) end), - - cmd("tabd[o]", "Execute command in each tab.", - function (w, a) w:each_tab(function (v) w:run_cmd(":" .. a) end) end), - - cmd("tabdu[plicate]", "Duplicate current tab.", - function (w) w:new_tab(w.view.history) end), - - cmd("tabfir[st]", "Switch to first tab.", - function (w) w:goto_tab(1) end), - - cmd("tabl[ast]", "Switch to last tab.", - function (w) w:goto_tab(-1) end), - - cmd("tabn[ext]", "Switch to the next tab.", - function (w) w:next_tab() end), - - cmd("tabp[revious]", "Switch to the previous tab.", - function (w) w:prev_tab() end), - - cmd("q[uit]", "Close the current window.", - function (w, a, o) w:close_win(o.bang) end), - - cmd({"viewsource", "vs"}, "View the source code of the current document.", - function (w, a, o) w:toggle_source(not o.bang and true or nil) end), - - cmd({"wqall", "wq"}, "Save the session and quit.", - function (w, a, o) w:save_session() w:close_win(o.bang) end), - - cmd("lua", "Evaluate Lua snippet.", function (w, a) - if a then - local ret = assert( - loadstring("return function(w) return "..a.." end"))()(w) - if ret then print(ret) end - else - w:set_mode("lua") - end - end), - - cmd("dump", "Dump current tabs html to file.", - function (w, a) - local fname = string.gsub(w.win.title, '[^%w%.%-]', '_')..'.html' -- sanitize filename - local file = a or luakit.save_file("Save file", w.win, xdg.download_dir or '.', fname) - if file then - local fd = assert(io.open(file, "w"), "failed to open: " .. file) - local html = assert(w.view:eval_js("document.documentElement.outerHTML"), "Unable to get HTML") - assert(fd:write(html), "unable to save html") - io.close(fd) - w:notify("Dumped HTML to: " .. file) - end - end), -}) - --- vim: et:sw=4:ts=8:sts=4:tw=80 diff --git a/.config/luakit/globals.lua b/.config/luakit/globals.lua deleted file mode 100644 index e70ae95..0000000 --- a/.config/luakit/globals.lua +++ /dev/null @@ -1,87 +0,0 @@ --- Global variables for luakit -globals = { - homepage = "about:blank", - -- homepage = "http://github.com/mason-larobina/luakit", - scroll_step = 40, - zoom_step = 0.1, - max_cmd_history = 100, - max_srch_history = 100, - -- http_proxy = "http://example.com:3128", - default_window_size = "800x600", - - -- Disables loading of hostnames from /etc/hosts (for large host files) - -- load_etc_hosts = false, - -- Disables checking if a filepath exists in search_open function - -- check_filepath = false, -} - --- Make useragent -local _, arch = luakit.spawn_sync("uname -sm") --- Only use the luakit version if in date format (reduces identifiability) -local lkv = string.match(luakit.version, "^(%d+.%d+.%d+)") -globals.useragent = string.format("Mozilla/5.0 (%s) AppleWebKit/%s+ (KHTML, like Gecko) WebKitGTK+/%s luakit%s", - string.sub(arch, 1, -2), luakit.webkit_user_agent_version, - luakit.webkit_version, (lkv and ("/" .. lkv)) or "") - --- Search common locations for a ca file which is used for ssl connection validation. -local ca_files = { - -- $XDG_DATA_HOME/luakit/ca-certificates.crt - luakit.data_dir .. "/ca-certificates.crt", - "/etc/certs/ca-certificates.crt", - "/etc/ssl/certs/ca-certificates.crt", -} --- Use the first ca-file found -for _, ca_file in ipairs(ca_files) do - if os.exists(ca_file) then - soup.ssl_ca_file = ca_file - break - end -end - --- Change to stop navigation sites with invalid or expired ssl certificates -soup.ssl_strict = false - --- Set cookie acceptance policy -cookie_policy = { always = 0, never = 1, no_third_party = 2 } -soup.accept_policy = cookie_policy.always - --- List of search engines. Each item must contain a single %s which is --- replaced by URI encoded search terms. All other occurances of the percent --- character (%) may need to be escaped by placing another % before or after --- it to avoid collisions with lua's string.format characters. --- See: http://www.lua.org/manual/5.1/manual.html#pdf-string.format -search_engines = { - duckduckgo = "https://duckduckgo.com/?q=%s", - github = "https://github.com/search?q=%s", - google = "https://google.com/search?q=%s", - imdb = "http://www.imdb.com/find?s=all&q=%s", - wikipedia = "https://en.wikipedia.org/wiki/Special:Search?search=%s", - aur = "https://aur.archlinux.org/packages.php?O=0&K=%s&do_Search=Go", - aw = "https://wiki.archlinux.org/index.php/Special:Search?fulltext=Search&search=%s", -} - --- Set google as fallback search engine -search_engines.default = search_engines.duckduckgo --- Use this instead to disable auto-searching ---search_engines.default = "%s" - --- Per-domain webview properties --- See http://webkitgtk.org/reference/webkitgtk/stable/WebKitWebSettings.html -domain_props = { --[[ - ["all"] = { - enable_scripts = false, - enable_plugins = false, - enable_private_browsing = false, - user_stylesheet_uri = "", - }, - ["youtube.com"] = { - enable_scripts = true, - enable_plugins = true, - }, - ["bbs.archlinux.org"] = { - user_stylesheet_uri = "file://" .. luakit.data_dir .. "/styles/dark.css", - enable_private_browsing = true, - }, ]] -} - --- vim: et:sw=4:ts=8:sts=4:tw=80 diff --git a/.config/luakit/modes.lua b/.config/luakit/modes.lua deleted file mode 100644 index bd15c67..0000000 --- a/.config/luakit/modes.lua +++ /dev/null @@ -1,163 +0,0 @@ -------------------------------- --- luakit mode configuration -- -------------------------------- - --- Table of modes and their callback hooks -local modes = {} -local lousy = require "lousy" -local join = lousy.util.table.join -local order = 0 - --- Add new mode table (optionally merges with original mode) -function new_mode(name, desc, mode, replace) - assert(string.match(name, "^[%w-_]+$"), "invalid mode name: " .. name) - -- Detect optional description - if type(desc) == "table" then - desc, mode, replace = nil, desc, mode - end - local traceback = debug.traceback("Creation traceback:", 2) - order = order + 1 - modes[name] = join({ order = order, traceback = traceback }, - (not replace and modes[name]) or {}, mode or {}, - { name = name, desc = desc }) -end - --- Get mode table -function get_mode(name) return modes[name] end - -function get_modes() return lousy.util.table.clone(modes) end - --- Attach window & input bar signals for mode hooks -window.init_funcs.modes_setup = function (w) - -- Calls the `enter` and `leave` mode hooks. - w:add_signal("mode-changed", function (_, name, ...) - local leave = (w.mode or {}).leave - - -- Get new modes functions/hooks/data - local mode = assert(modes[name], "invalid mode: " .. name) - - -- Call last modes leave hook. - if leave then leave(w) end - - -- Create w.mode object - w.mode = mode - - -- Update window binds - w:update_binds(name) - - -- Call new modes enter hook. - if mode.enter then mode.enter(w, ...) end - - w:emit_signal("mode-entered", mode) - end) - - local input = w.ibar.input - - -- Calls the changed hook on input widget changed. - input:add_signal("changed", function () - local changed = w.mode.changed - if changed then changed(w, input.text) end - end) - - input:add_signal("property::position", function () - local move_cursor = w.mode.move_cursor - if move_cursor then move_cursor(w, input.position) end - end) - - -- Calls the `activate` hook on input widget activate. - input:add_signal("activate", function () - local mode = w.mode - if mode and mode.activate then - local text, hist = input.text, mode.history - if mode.activate(w, text) == false then return end - -- Check if last history item is identical - if hist and hist.items and hist.items[hist.len or -1] ~= text then - table.insert(hist.items, text) - end - end - end) -end - --- Add mode related window methods -window.methods.set_mode = lousy.mode.set -local mget = lousy.mode.get -window.methods.is_mode = function (w, name) return name == mget(w) end - --- Setup normal mode -new_mode("normal", [[When luakit first starts you will find yourself in this - mode.]], { - enter = function (w) - w:set_prompt() - w:set_input() - end, -}) - -new_mode("all", [[Special meta-mode in which the bindings for this mode are - present in all modes.]]) - --- Setup insert mode -new_mode("insert", [[When clicking on form fields luakit will enter the insert - mode which allows you to enter text in form fields without accidentally - triggering normal mode bindings.]], { - enter = function (w) - w:set_prompt("-- INSERT --") - w:set_input() - w.view:focus() - end, - -- Send key events to webview - passthrough = true, -}) - -new_mode("passthrough", [[Luakit will pass every key event to the WebView - until the user presses Escape.]], { - enter = function (w) - w:set_prompt("-- PASS THROUGH --") - w:set_input() - end, - -- Send key events to webview - passthrough = true, - -- Don't exit mode when clicking outside of form fields - reset_on_focus = false, - -- Don't exit mode on navigation - reset_on_navigation = false, -}) - --- Setup command mode -new_mode("command", [[Enter commands.]], { - enter = function (w) - w:set_prompt() - w:set_input(":") - end, - changed = function (w, text) - -- Auto-exit command mode if user backspaces ":" in the input bar. - if not string.match(text, "^:") then w:set_mode() end - end, - activate = function (w, text) - w:set_mode() - local cmd = string.sub(text, 2) - if not string.find(cmd, "%S") then return end - - local success, match = xpcall( - function () return w:match_cmd(cmd) end, - function (err) w:error(debug.traceback(err, 3)) end) - - if success and not match then - w:error(string.format("Not a browser command: %q", cmd)) - end - end, - history = {maxlen = 50}, -}) - -new_mode("lua", [[Execute arbitrary Lua commands within the luakit - environment.]], { - enter = function (w) - w:set_prompt(">") - w:set_input("") - end, - activate = function (w, text) - w:set_input("") - local ret = assert(loadstring("return function(w) return "..text.." end"))()(w) - if ret then print(ret) end - end, - history = {maxlen = 50}, -}) diff --git a/.config/luakit/rc.lua b/.config/luakit/rc.lua deleted file mode 100644 index e6ea88c..0000000 --- a/.config/luakit/rc.lua +++ /dev/null @@ -1,184 +0,0 @@ ------------------------------------------------------------------------ --- luakit configuration file, more information at http://luakit.org/ -- ------------------------------------------------------------------------ - -require "lfs" - -if unique then - unique.new("org.luakit") - -- Check for a running luakit instance - if unique.is_running() then - if uris[1] then - for _, uri in ipairs(uris) do - if lfs.attributes(uri) then uri = os.abspath(uri) end - unique.send_message("tabopen " .. uri) - end - else - unique.send_message("winopen") - end - luakit.quit() - end -end - --- Load library of useful functions for luakit -require "lousy" - --- Small util functions to print output (info prints only when luakit.verbose is true) -function warn(...) io.stderr:write(string.format(...) .. "\n") end -function info(...) if luakit.verbose then io.stdout:write(string.format(...) .. "\n") end end - --- Load users global config --- ("$XDG_CONFIG_HOME/luakit/globals.lua" or "/etc/xdg/luakit/globals.lua") -require "globals" - --- Load users theme --- ("$XDG_CONFIG_HOME/luakit/theme.lua" or "/etc/xdg/luakit/theme.lua") -lousy.theme.init(lousy.util.find_config("theme.lua")) -theme = assert(lousy.theme.get(), "failed to load theme") - --- Load users window class --- ("$XDG_CONFIG_HOME/luakit/window.lua" or "/etc/xdg/luakit/window.lua") -require "window" - --- Load users webview class --- ("$XDG_CONFIG_HOME/luakit/webview.lua" or "/etc/xdg/luakit/webview.lua") -require "webview" - --- Load users mode configuration --- ("$XDG_CONFIG_HOME/luakit/modes.lua" or "/etc/xdg/luakit/modes.lua") -require "modes" - --- Load users keybindings --- ("$XDG_CONFIG_HOME/luakit/binds.lua" or "/etc/xdg/luakit/binds.lua") -require "binds" - ----------------------------------- --- Optional user script loading -- ----------------------------------- - -require "webinspector" - --- Add sqlite3 cookiejar -require "cookies" - --- Cookie blocking by domain (extends cookies module) --- Add domains to the whitelist at "$XDG_CONFIG_HOME/luakit/cookie.whitelist" --- and blacklist at "$XDG_CONFIG_HOME/luakit/cookie.blacklist". --- Each domain must be on it's own line and you may use "*" as a --- wildcard character (I.e. "*google.com") ---require "cookie_blocking" - --- Block all cookies by default (unless whitelisted) ---cookies.default_allow = false - --- Add uzbl-like form filling -require "formfiller" - --- Add proxy support & manager -require "proxy" - --- Add quickmarks support & manager -require "quickmarks" - --- Add session saving/loading support -require "session" - --- Add command to list closed tabs & bind to open closed tabs -require "undoclose" - --- Add command to list tab history items -require "tabhistory" - --- Add greasemonkey-like javascript userscript support -require "userscripts" - --- Add bookmarks support -require "bookmarks" -require "bookmarks_chrome" - --- Add download support -require "downloads" -require "downloads_chrome" - --- Example using xdg-open for opening downloads / showing download folders ---downloads.add_signal("open-file", function (file, mime) --- luakit.spawn(string.format("xdg-open %q", file)) --- return true ---end) - --- Add vimperator-like link hinting & following -require "follow" - --- Use a custom charater set for hint labels ---local s = follow.label_styles ---follow.label_maker = s.sort(s.reverse(s.charset("asdfqwerzxcv"))) - --- Match only hint labels ---follow.pattern_maker = follow.pattern_styles.match_label - --- Add command history -require "cmdhist" - --- Add search mode & binds -require "search" - --- Add ordering of new tabs -require "taborder" - --- Save web history -require "history" -require "history_chrome" - -require "introspector" - --- Add command completion -require "completion" - --- NoScript plugin, toggle scripts and or plugins on a per-domain basis. --- `,ts` to toggle scripts, `,tp` to toggle plugins, `,tr` to reset. --- Remove all "enable_scripts" & "enable_plugins" lines from your --- domain_props table (in config/globals.lua) as this module will conflict. ---require "noscript" - -require "follow_selected" -require "go_input" -require "go_next_prev" -require "go_up" - ------------------------------ --- End user script loading -- ------------------------------ - --- Restore last saved session -local w = (session and session.restore()) -if w then - for i, uri in ipairs(uris) do - w:new_tab(uri, i == 1) - end -else - -- Or open new window - window.new(uris) -end - -------------------------------------------- --- Open URIs from other luakit instances -- -------------------------------------------- - -if unique then - unique.add_signal("message", function (msg, screen) - local cmd, arg = string.match(msg, "^(%S+)%s*(.*)") - local w = lousy.util.table.values(window.bywidget)[1] - if cmd == "tabopen" then - w:new_tab(arg) - elseif cmd == "winopen" then - w = window.new((arg ~= "") and { arg } or {}) - end - w.win.screen = screen - w.win.urgency_hint = true - end) -end - -require "adblock" -require "adblock_chrome" - --- vim: et:sw=4:ts=8:sts=4:tw=80 diff --git a/.config/luakit/theme.lua b/.config/luakit/theme.lua deleted file mode 100644 index 6ac6c17..0000000 --- a/.config/luakit/theme.lua +++ /dev/null @@ -1,69 +0,0 @@ --------------------------- --- Default luakit theme -- --------------------------- - -local theme = {} - --- Default settings -theme.font = "monospace normal 9" -theme.fg = "#fff" -theme.bg = "#000" - --- Genaral colours -theme.success_fg = "#0f0" -theme.loaded_fg = "#33AADD" -theme.error_fg = "#FFF" -theme.error_bg = "#F00" - --- Warning colours -theme.warning_fg = "#F00" -theme.warning_bg = "#FFF" - --- Notification colours -theme.notif_fg = "#444" -theme.notif_bg = "#FFF" - --- Menu colours -theme.menu_fg = "#000" -theme.menu_bg = "#fff" -theme.menu_selected_fg = "#000" -theme.menu_selected_bg = "#FF0" -theme.menu_title_bg = "#fff" -theme.menu_primary_title_fg = "#f00" -theme.menu_secondary_title_fg = "#666" - --- Proxy manager -theme.proxy_active_menu_fg = '#000' -theme.proxy_active_menu_bg = '#FFF' -theme.proxy_inactive_menu_fg = '#888' -theme.proxy_inactive_menu_bg = '#FFF' - --- Statusbar specific -theme.sbar_fg = "#fff" -theme.sbar_bg = "#000" - --- Downloadbar specific -theme.dbar_fg = "#fff" -theme.dbar_bg = "#000" -theme.dbar_error_fg = "#F00" - --- Input bar specific -theme.ibar_fg = "#000" -theme.ibar_bg = "#fff" - --- Tab label -theme.tab_fg = "#888" -theme.tab_bg = "#222" -theme.tab_ntheme = "#ddd" -theme.selected_fg = "#fff" -theme.selected_bg = "#000" -theme.selected_ntheme = "#ddd" -theme.loading_fg = "#33AADD" -theme.loading_bg = "#000" - --- Trusted/untrusted ssl colours -theme.trust_fg = "#0F0" -theme.notrust_fg = "#F00" - -return theme --- vim: et:sw=4:ts=8:sts=4:tw=80 diff --git a/.config/luakit/webview.lua b/.config/luakit/webview.lua deleted file mode 100644 index a7a7a59..0000000 --- a/.config/luakit/webview.lua +++ /dev/null @@ -1,350 +0,0 @@ --------------------------- --- WebKit WebView class -- --------------------------- - --- Webview class table -webview = {} - --- Table of functions which are called on new webview widgets. -webview.init_funcs = { - -- Set useragent - set_useragent = function (view, w) - view.user_agent = globals.useragent - end, - - -- Check if checking ssl certificates - checking_ssl = function (view, w) - local ca_file = soup.ssl_ca_file - if ca_file and os.exists(ca_file) then - w.checking_ssl = true - end - end, - - -- Update window and tab titles - title_update = function (view, w) - view:add_signal("property::title", function (v) - w:update_tablist() - if w.view == v then - w:update_win_title() - end - end) - end, - - -- Update uri label in statusbar - uri_update = function (view, w) - view:add_signal("property::uri", function (v) - w:update_tablist() - if w.view == v then - w:update_uri() - end - end) - end, - - -- Update history indicator - hist_update = function (view, w) - view:add_signal("load-status", function (v, status) - if w.view == v then - w:update_hist() - end - end) - end, - - -- Update tab titles - tablist_update = function (view, w) - view:add_signal("load-status", function (v, status) - if status == "provisional" or status == "finished" or status == "failed" then - w:update_tablist() - end - end) - end, - - -- Update scroll widget - scroll_update = function (view, w) - view:add_signal("expose", function (v) - if w.view == v then - w:update_scroll() - end - end) - end, - - -- Update progress widget - progress_update = function (view, w) - for _, sig in ipairs({"load-status", "property::progress"}) do - view:add_signal(sig, function (v) - if w.view == v then - w:update_progress() - w:update_ssl() - end - end) - end - end, - - -- Display hovered link in statusbar - link_hover_display = function (view, w) - view:add_signal("link-hover", function (v, link) - if w.view == v and link then - w:update_uri(link) - end - end) - view:add_signal("link-unhover", function (v) - if w.view == v then - w:update_uri() - end - end) - end, - - -- Clicking a form field automatically enters insert mode. - form_insert_mode = function (view, w) - view:add_signal("button-press", function (v, mods, button, context) - -- Clear start search marker - (w.search_state or {}).marker = nil - - if button == 1 and context.editable then - view:emit_signal("form-active") - end - end) - -- Emit root-active event in button release to prevent "missing" - -- buttons or links when the input bar hides. - view:add_signal("button-release", function (v, mods, button, context) - if button == 1 and not context.editable then - view:emit_signal("root-active") - end - end) - view:add_signal("form-active", function () - if not w.mode.passthrough then - w:set_mode("insert") - end - end) - view:add_signal("root-active", function () - if w.mode.reset_on_focus ~= false then - w:set_mode() - end - end) - end, - - -- Catch keys in non-passthrough modes - mode_key_filter = function (view, w) - view:add_signal("key-press", function () - if not w.mode.passthrough then - return true - end - end) - end, - - -- Try to match a button event to a users button binding else let the - -- press hit the webview. - button_bind_match = function (view, w) - view:add_signal("button-release", function (v, mods, button, context) - (w.search_state or {}).marker = nil - if w:hit(mods, button, { context = context }) then - return true - end - end) - end, - - -- Reset the mode on navigation - mode_reset_on_nav = function (view, w) - view:add_signal("load-status", function (v, status) - if status == "provisional" and w.view == v then - if w.mode.reset_on_navigation ~= false then - w:set_mode() - end - end - end) - end, - - -- Domain properties - domain_properties = function (view, w) - view:add_signal("load-status", function (v, status) - if status ~= "committed" or v.uri == "about:blank" then return end - -- Get domain - local domain = lousy.uri.parse(v.uri).host - -- Strip leading www. - domain = string.match(domain or "", "^www%.(.+)") or domain or "all" - -- Build list of domain props tables to join & load. - -- I.e. for luakit.org load .luakit.org, luakit.org, .org - local props = {domain_props.all or {}, domain_props[domain] or {}} - repeat - table.insert(props, 2, domain_props["."..domain] or {}) - domain = string.match(domain, "%.(.+)") - until not domain - -- Join all property tables - for k, v in pairs(lousy.util.table.join(unpack(props))) do - info("Domain prop: %s = %s (%s)", k, tostring(v), domain) - view[k] = v - end - end) - end, - - -- Action to take on mime type decision request. - mime_decision = function (view, w) - -- Return true to accept or false to reject from this signal. - view:add_signal("mime-type-decision", function (v, uri, mime) - info("Requested link: %s (%s)", uri, mime) - -- i.e. block binary files like *.exe - --if mime == "application/octet-stream" then - -- return false - --end - end) - end, - - -- Action to take on window open request. - --window_decision = function (view, w) - -- view:add_signal("new-window-decision", function (v, uri, reason) - -- if reason == "link-clicked" then - -- window.new({uri}) - -- else - -- w:new_tab(uri) - -- end - -- return true - -- end) - --end, - - create_webview = function (view, w) - -- Return a newly created webview in a new tab - view:add_signal("create-web-view", function (v) - return w:new_tab() - end) - end, - - -- Creates context menu popup from table (and nested tables). - -- Use `true` for menu separators. - --populate_popup = function (view, w) - -- view:add_signal("populate-popup", function (v) - -- return { - -- true, - -- { "_Toggle Source", function () w:toggle_source() end }, - -- { "_Zoom", { - -- { "Zoom _In", function () w:zoom_in() end }, - -- { "Zoom _Out", function () w:zoom_out() end }, - -- true, - -- { "Zoom _Reset", function () w:zoom_set() end }, }, }, - -- } - -- end) - --end, - - -- Action to take on resource request. - resource_request_decision = function (view, w) - view:add_signal("resource-request-starting", function(v, uri) - info("Requesting: %s", uri) - -- Return false to cancel the request. - end) - end, -} - --- These methods are present when you index a window instance and no window --- method is found in `window.methods`. The window then checks if there is an --- active webview and calls the following methods with the given view instance --- as the first argument. All methods must take `view` & `w` as the first two --- arguments. -webview.methods = { - -- Reload with or without ignoring cache - reload = function (view, w, bypass_cache) - if bypass_cache then - view:reload_bypass_cache() - else - view:reload() - end - end, - - -- Toggle source view - toggle_source = function (view, w, show) - if show == nil then - view.view_source = not view.view_source - else - view.view_source = show - end - view:reload() - end, - - -- Zoom functions - zoom_in = function (view, w, step, full_zoom) - view.full_content_zoom = not not full_zoom - step = step or globals.zoom_step or 0.1 - view.zoom_level = view.zoom_level + step - end, - - zoom_out = function (view, w, step, full_zoom) - view.full_content_zoom = not not full_zoom - step = step or globals.zoom_step or 0.1 - view.zoom_level = math.max(0.01, view.zoom_level) - step - end, - - zoom_set = function (view, w, level, full_zoom) - view.full_content_zoom = not not full_zoom - view.zoom_level = level or 1.0 - end, - - -- History traversing functions - back = function (view, w, n) - view:go_back(n or 1) - end, - - forward = function (view, w, n) - view:go_forward(n or 1) - end, -} - -function webview.methods.scroll(view, w, new) - local s = view.scroll - for _, axis in ipairs{ "x", "y" } do - -- Relative px movement - if rawget(new, axis.."rel") then - s[axis] = s[axis] + new[axis.."rel"] - - -- Relative page movement - elseif rawget(new, axis .. "pagerel") then - s[axis] = s[axis] + math.ceil(s[axis.."page_size"] * new[axis.."pagerel"]) - - -- Absolute px movement - elseif rawget(new, axis) then - local n = new[axis] - if n == -1 then - s[axis] = s[axis.."max"] - else - s[axis] = n - end - - -- Absolute page movement - elseif rawget(new, axis.."page") then - s[axis] = math.ceil(s[axis.."page_size"] * new[axis.."page"]) - - -- Absolute percent movement - elseif rawget(new, axis .. "pct") then - s[axis] = math.ceil(s[axis.."max"] * (new[axis.."pct"]/100)) - end - end -end - -function webview.new(w) - local view = widget{type = "webview"} - - view.show_scrollbars = false - view.enforce_96_dpi = false - - -- Call webview init functions - for k, func in pairs(webview.init_funcs) do - func(view, w) - end - return view -end - --- Insert webview method lookup on window structure -table.insert(window.indexes, 1, function (w, k) - if k == "view" then - local view = w.tabs[w.tabs:current()] - if view and type(view) == "widget" and view.type == "webview" then - w.view = view - return view - end - end - -- Lookup webview method - local func = webview.methods[k] - if not func then return end - local view = w.view - if view then - return function (_, ...) return func(view, w, ...) end - end -end) - --- vim: et:sw=4:ts=8:sts=4:tw=80 diff --git a/.config/luakit/window.lua b/.config/luakit/window.lua deleted file mode 100644 index 5e921d6..0000000 --- a/.config/luakit/window.lua +++ /dev/null @@ -1,859 +0,0 @@ ------------------- --- Window class -- ------------------- - -require "lfs" - --- Window class table -window = {} - --- List of active windows by window widget -window.bywidget = setmetatable({}, { __mode = "k" }) - --- Widget construction aliases -local function entry() return widget{type="entry"} end -local function eventbox() return widget{type="eventbox"} end -local function hbox() return widget{type="hbox"} end -local function label() return widget{type="label"} end -local function notebook() return widget{type="notebook"} end -local function vbox() return widget{type="vbox"} end - --- Build and pack window widgets -function window.build() - -- Create a table for widgets and state variables for a window - local w = { - win = widget{type="window"}, - ebox = eventbox(), - layout = vbox(), - paned = widget{type="vpaned"}, - tabs = notebook(), - -- Tablist widget - tablist = lousy.widget.tablist(), - -- Status bar widgets - sbar = { - layout = hbox(), - ebox = eventbox(), - -- Left aligned widgets - l = { - layout = hbox(), - ebox = eventbox(), - uri = label(), - hist = label(), - loaded = label(), - }, - -- Fills space between the left and right aligned widgets - sep = eventbox(), - -- Right aligned widgets - r = { - layout = hbox(), - ebox = eventbox(), - buf = label(), - ssl = label(), - tabi = label(), - scroll = label(), - }, - }, - - -- Vertical menu window widget (completion results, bookmarks, qmarks, ..) - menu = lousy.widget.menu(), - - -- Input bar widgets - ibar = { - layout = hbox(), - ebox = eventbox(), - prompt = label(), - input = entry(), - }, - closed_tabs = {} - } - - -- Assemble window - w.ebox.child = w.paned - w.paned:pack1(w.layout) - w.win.child = w.ebox - - -- Pack tablist - w.layout:pack(w.tablist.widget) - - -- Pack notebook - w.layout:pack(w.tabs, { expand = true, fill = true }) - - -- Pack left-aligned statusbar elements - local l = w.sbar.l - l.layout:pack(l.uri) - l.layout:pack(l.hist) - l.layout:pack(l.loaded) - l.ebox.child = l.layout - - -- Pack right-aligned statusbar elements - local r = w.sbar.r - r.layout:pack(r.buf) - r.layout:pack(r.ssl) - r.layout:pack(r.tabi) - r.layout:pack(r.scroll) - r.ebox.child = r.layout - - -- Pack status bar elements - local s = w.sbar - s.layout:pack(l.ebox) - s.layout:pack(s.sep, { expand = true, fill = true }) - s.layout:pack(r.ebox) - s.ebox.child = s.layout - w.layout:pack(s.ebox) - - -- Pack menu widget - w.layout:pack(w.menu.widget) - w.menu:hide() - - -- Pack input bar - local i = w.ibar - i.layout:pack(i.prompt) - i.layout:pack(i.input, { expand = true, fill = true }) - i.ebox.child = i.layout - w.layout:pack(i.ebox) - - -- Other settings - i.input.show_frame = false - w.tabs.show_tabs = false - l.loaded:hide() - l.hist:hide() - l.uri.selectable = true - r.ssl:hide() - - -- Allows indexing of window struct by window widget - window.bywidget[w.win] = w - - return w -end - --- Table of functions to call on window creation. Normally used to add signal --- handlers to the new windows widgets. -window.init_funcs = { - -- Attach notebook widget signals - notebook_signals = function (w) - w.tabs:add_signal("page-added", function (nbook, view, idx) - luakit.idle_add(function () - w:update_tab_count() - w:update_tablist() - return false - end) - end) - w.tabs:add_signal("switch-page", function (nbook, view, idx) - w.view = nil - w:set_mode() - -- Update widgets after tab switch - luakit.idle_add(function () - w:update_tab_count() - w:update_win_title() - w:update_uri() - w:update_progress() - w:update_tablist() - w:update_buf() - w:update_ssl() - w:update_hist() - return false - end) - end) - w.tabs:add_signal("page-reordered", function (nbook, view, idx) - w:update_tab_count() - w:update_tablist() - end) - end, - - last_win_check = function (w) - w.win:add_signal("destroy", function () - -- call the quit function if this was the last window left - if #luakit.windows == 0 then luakit.quit() end - if w.close_win then w:close_win() end - end) - end, - - key_press_match = function (w) - w.win:add_signal("key-press", function (_, mods, key) - -- Match & exec a bind - local success, match = xpcall( - function () return w:hit(mods, key) end, - function (err) w:error(debug.traceback(err, 3)) end) - - if success and match then - return true - end - end) - end, - - tablist_tab_click = function (w) - w.tablist:add_signal("tab-clicked", function (_, index, mods, button) - if button == 1 then - w.tabs:switch(index) - return true - elseif button == 2 then - w:close_tab(w.tabs[index]) - return true - end - end) - end, - - apply_window_theme = function (w) - local s, i = w.sbar, w.ibar - - -- Set foregrounds - for wi, v in pairs({ - [s.l.uri] = theme.uri_sbar_fg, - [s.l.hist] = theme.hist_sbar_fg, - [s.l.loaded] = theme.sbar_loaded_fg, - [s.r.buf] = theme.buf_sbar_fg, - [s.r.tabi] = theme.tabi_sbar_fg, - [s.r.scroll] = theme.scroll_sbar_fg, - [i.prompt] = theme.prompt_ibar_fg, - [i.input] = theme.input_ibar_fg, - }) do wi.fg = v end - - -- Set backgrounds - for wi, v in pairs({ - [s.l.ebox] = theme.sbar_bg, - [s.r.ebox] = theme.sbar_bg, - [s.sep] = theme.sbar_bg, - [s.ebox] = theme.sbar_bg, - [i.ebox] = theme.ibar_bg, - [i.input] = theme.input_ibar_bg, - }) do wi.bg = v end - - -- Set fonts - for wi, v in pairs({ - [s.l.uri] = theme.uri_sbar_font, - [s.l.hist] = theme.hist_sbar_font, - [s.l.loaded] = theme.sbar_loaded_font, - [s.r.buf] = theme.buf_sbar_font, - [s.r.ssl] = theme.ssl_sbar_font, - [s.r.tabi] = theme.tabi_sbar_font, - [s.r.scroll] = theme.scroll_sbar_font, - [i.prompt] = theme.prompt_ibar_font, - [i.input] = theme.input_ibar_font, - }) do wi.font = v end - end, - - set_default_size = function (w) - local size = globals.default_window_size or "800x600" - if string.match(size, "^%d+x%d+$") then - w.win:set_default_size(string.match(size, "^(%d+)x(%d+)$")) - else - warn("E: window.lua: invalid window size: %q", size) - end - end, - - set_window_icon = function (w) - local path = (luakit.dev_paths and os.exists("./extras/luakit.png")) or - os.exists("/usr/share/pixmaps/luakit.png") - if path then w.win.icon = path end - end, - - clear_urgency_hint = function (w) - w.win:add_signal("focus", function () - w.win.urgency_hint = false - end) - end, -} - --- Helper functions which operate on the window widgets or structure. -window.methods = { - -- Wrapper around the bind plugin's hit method - hit = function (w, mods, key, opts) - local opts = lousy.util.table.join(opts or {}, { - enable_buffer = w:is_mode("normal"), - buffer = w.buffer, - }) - - local caught, newbuf = lousy.bind.hit(w, w.binds, mods, key, opts) - if w.win then -- Check binding didn't cause window to exit - w.buffer = newbuf - w:update_buf() - end - return caught - end, - - -- Wrapper around the bind plugin's match_cmd method - match_cmd = function (w, buffer) - return lousy.bind.match_cmd(w, get_mode("command").binds, buffer) - end, - - -- enter command or characters into command line - enter_cmd = function (w, cmd, opts) - w:set_mode("command") - w:set_input(cmd, opts) - end, - - -- run command as if typed into the command line - run_cmd = function (w, cmd, opts) - w:enter_cmd(cmd, opts) - w:activate() - end, - - -- insert a string into the command line at the current cursor position - insert_cmd = function (w, str) - if not str then return end - local i = w.ibar.input - local text = i.text - local pos = i.position - local left, right = string.sub(text, 1, pos), string.sub(text, pos+1) - i.text = left .. str .. right - i.position = pos + #str - end, - - -- Emulates pressing the Return key in input field - activate = function (w) - w.ibar.input:emit_signal("activate") - end, - - del_word = function (w) - local i = w.ibar.input - local text = i.text - local pos = i.position - if text and #text > 1 and pos > 1 then - local left, right = string.sub(text, 2, pos), string.sub(text, pos+1) - if not string.find(left, "%s") then - left = "" - elseif string.find(left, "%w+%s*$") then - left = string.sub(left, 0, string.find(left, "%w+%s*$") - 1) - elseif string.find(left, "%W+%s*$") then - left = string.sub(left, 0, string.find(left, "%W+%s*$") - 1) - end - i.text = string.sub(text, 1, 1) .. left .. right - i.position = #left + 1 - end - end, - - del_line = function (w) - local i = w.ibar.input - if not string.match(i.text, "^[:/?]$") then - i.text = string.sub(i.text, 1, 1) - i.position = -1 - end - end, - - del_backward_char = function (w) - local i = w.ibar.input - local text = i.text - local pos = i.position - - if pos > 1 then - i.text = string.sub(text, 0, pos - 1) .. string.sub(text, pos + 1) - i.position = pos - 1 - end - end, - - del_forward_char = function (w) - local i = w.ibar.input - local text = i.text - local pos = i.position - - i.text = string.sub(text, 0, pos) .. string.sub(text, pos + 2) - i.position = pos - end, - - beg_line = function (w) - local i = w.ibar.input - i.position = 1 - end, - - end_line = function (w) - local i = w.ibar.input - i.position = -1 - end, - - forward_char = function (w) - local i = w.ibar.input - i.position = i.position + 1 - end, - - backward_char = function (w) - local i = w.ibar.input - local pos = i.position - if pos > 1 then - i.position = pos - 1 - end - end, - - forward_word = function (w) - local i = w.ibar.input - local text = i.text - local pos = i.position - if text and #text > 1 then - local right = string.sub(text, pos+1) - if string.find(right, "%w+") then - local _, move = string.find(right, "%w+") - i.position = pos + move - end - end - end, - - backward_word = function (w) - local i = w.ibar.input - local text = i.text - local pos = i.position - if text and #text > 1 and pos > 1 then - local left = string.reverse(string.sub(text, 2, pos)) - if string.find(left, "%w+") then - local _, move = string.find(left, "%w+") - i.position = pos - move - end - end - end, - - -- Shows a notification until the next keypress of the user. - notify = function (w, msg, set_mode) - if set_mode ~= false then w:set_mode() end - w:set_prompt(msg, { fg = theme.notif_fg, bg = theme.notif_bg }) - end, - - warning = function (w, msg, set_mode) - if set_mode ~= false then w:set_mode() end - w:set_prompt(msg, { fg = theme.warning_fg, bg = theme.warning_bg }) - end, - - error = function (w, msg, set_mode) - if set_mode ~= false then w:set_mode() end - w:set_prompt("Error: "..msg, { fg = theme.error_fg, bg = theme.error_bg }) - end, - - -- Set and display the prompt - set_prompt = function (w, text, opts) - local prompt, ebox, opts = w.ibar.prompt, w.ibar.ebox, opts or {} - prompt:hide() - -- Set theme - fg, bg = opts.fg or theme.ibar_fg, opts.bg or theme.ibar_bg - if prompt.fg ~= fg then prompt.fg = fg end - if ebox.bg ~= bg then ebox.bg = bg end - -- Set text or remain hidden - if text then - prompt.text = lousy.util.escape(text) - prompt:show() - end - end, - - -- Set display and focus the input bar - set_input = function (w, text, opts) - local input, opts = w.ibar.input, opts or {} - input:hide() - -- Set theme - fg, bg = opts.fg or theme.ibar_fg, opts.bg or theme.ibar_bg - if input.fg ~= fg then input.fg = fg end - if input.bg ~= bg then input.bg = bg end - -- Set text or remain hidden - if text then - input.text = "" - input:show() - input:focus() - input.text = text - input.position = opts.pos or -1 - end - end, - - -- GUI content update functions - update_tab_count = function (w) - w.sbar.r.tabi.text = string.format("[%d/%d]", w.tabs:current(), w.tabs:count()) - end, - - update_win_title = function (w) - local uri, title = w.view.uri, w.view.title - title = (title or "luakit") .. ((uri and " - " .. uri) or "") - local max = globals.max_title_len or 80 - if #title > max then title = string.sub(title, 1, max) .. "..." end - w.win.title = title - end, - - update_uri = function (w, link) - w.sbar.l.uri.text = lousy.util.escape((link and "Link: " .. link) - or (w.view and w.view.uri) or "about:blank") - end, - - update_progress = function (w) - local p = w.view.progress - local loaded = w.sbar.l.loaded - if not w.view:loading() or p == 1 then - loaded:hide() - else - loaded:show() - loaded.text = string.format("(%d%%)", p * 100) - end - end, - - update_scroll = function (w) - local scroll, label = w.view.scroll, w.sbar.r.scroll - local y, max, text = scroll.y, scroll.ymax - if max == 0 then text = "All" - elseif y == 0 then text = "Top" - elseif y == max then text = "Bot" - else text = string.format("%2d%%", (y / max) * 100) - end - if label.text ~= text then label.text = text end - end, - - update_ssl = function (w) - local trusted = w.view:ssl_trusted() - local ssl = w.sbar.r.ssl - if trusted ~= nil and not w.checking_ssl then - ssl.fg = theme.notrust_fg - ssl.text = "(nocheck)" - ssl:show() - elseif trusted == true then - ssl.fg = theme.trust_fg - ssl.text = "(trust)" - ssl:show() - elseif trusted == false then - ssl.fg = theme.notrust_fg - ssl.text = "(notrust)" - ssl:show() - else - ssl:hide() - end - end, - - update_hist = function (w) - local hist = w.sbar.l.hist - local back, forward = w.view:can_go_back(), w.view:can_go_forward() - local s = (back and "+" or "") .. (forward and "-" or "") - if s ~= "" then - hist.text = '['..s..']' - hist:show() - else - hist:hide() - end - end, - - update_buf = function (w) - local buf = w.sbar.r.buf - if w.buffer then - buf.text = lousy.util.escape(string.format(" %-3s", w.buffer)) - buf:show() - else - buf:hide() - end - end, - - update_binds = function (w, mode) - -- Generate the list of active key & buffer binds for this mode - w.binds = lousy.util.table.join((get_mode(mode) or {}).binds or {}, get_mode('all').binds or {}) - -- Clear & hide buffer - w.buffer = nil - w:update_buf() - end, - - update_tablist = function (w) - local current = w.tabs:current() - local fg, bg, nfg, snfg = theme.tab_fg, theme.tab_bg, theme.tab_ntheme, theme.selected_ntheme - local lfg, bfg, gfg = theme.tab_loading_fg, theme.tab_notrust_fg, theme.tab_trust_fg - local escape = lousy.util.escape - local tabs, tfmt = {}, ' <span foreground="%s">%s</span> %s' - - for i, view in ipairs(w.tabs.children) do - -- Get tab number theme - local ntheme = nfg - if view:loading() then -- Show loading on all tabs - ntheme = lfg - elseif current == i then -- Show ssl trusted/untrusted on current tab - local trusted = view:ssl_trusted() - ntheme = snfg - if trusted == false or (trusted ~= nil and not w.checking_ssl) then - ntheme = bfg - elseif trusted then - ntheme = gfg - end - end - local title = view.title or view.uri or "(Untitled)" - tabs[i] = { - title = string.format(tfmt, ntheme or fg, i, escape(title)), - fg = (current == i and theme.tab_selected_fg) or fg, - bg = (current == i and theme.tab_selected_bg) or bg, - } - end - - if #tabs < 2 then tabs, current = {}, 0 end - w.tablist:update(tabs, current) - end, - - new_tab = function (w, arg, switch, order) - local view - -- Use blank tab first - if w.has_blank and w.tabs:count() == 1 and w.tabs[1].uri == "about:blank" then - view = w.tabs[1] - end - w.has_blank = nil - -- Make new webview widget - if not view then - view = webview.new(w) - -- Get tab order function - if not order and taborder then - order = (switch == false and taborder.default_bg) - or taborder.default - end - pos = w.tabs:insert((order and order(w, view)) or -1, view) - if switch ~= false then w.tabs:switch(pos) end - end - -- Load uri or webview history table - if type(arg) == "string" then view.uri = arg - elseif type(arg) == "table" then view.history = arg end - -- Update statusbar widgets - w:update_tab_count() - w:update_tablist() - return view - end, - - -- close the current tab - close_tab = function (w, view, blank_last) - view = view or w.view - -- Treat a blank last tab as an empty notebook (if blank_last=true) - if blank_last ~= false and w.tabs:count() == 1 then - if not view:loading() and view.uri == "about:blank" then return end - w:new_tab("about:blank", false) - w.has_blank = true - end - -- Save tab history - local tab = {hist = view.history,} - -- And relative location - local index = w.tabs:indexof(view) - if index ~= 1 then tab.after = w.tabs[index-1] end - table.insert(w.closed_tabs, tab) - view:destroy() - w:update_tab_count() - w:update_tablist() - end, - - close_win = function (w, force) - -- Ask plugins if it's OK to close last window - if not force and (#luakit.windows == 1) then - local emsg = luakit.emit_signal("can-close", w) - if emsg then - assert(type(emsg) == "string", "invalid exit error message") - w:error(string.format("Can't close luakit: %s (force close " - .. "with :q! or :wq!)", emsg)) - return false - end - end - - w:emit_signal("close") - - -- Close all tabs - while w.tabs:count() ~= 0 do - w:close_tab(nil, false) - end - - -- Destroy tablist - w.tablist:destroy() - - -- Remove from window index - window.bywidget[w.win] = nil - - -- Clear window struct - w = setmetatable(w, {}) - - -- Recursively remove widgets from window - local children = lousy.util.recursive_remove(w.win) - -- Destroy all widgets - for i, c in ipairs(lousy.util.table.join(children, {w.win})) do - if c.hide then c:hide() end - c:destroy() - end - - -- Remove all window table vars - for k, _ in pairs(w) do w[k] = nil end - - -- Quit if closed last window - if #luakit.windows == 0 then luakit.quit() end - end, - - -- Navigate current view or open new tab - navigate = function (w, uri, view) - view = view or w.view - if view then - local js = string.match(uri, "^javascript:(.+)$") - if js then - return view:eval_js(luakit.uri_decode(js)) - end - view.uri = uri - else - return w:new_tab(uri) - end - end, - - -- Save, restart luakit and reload session. - restart = function (w) - -- Generate luakit launch command. - local args = {({string.gsub(luakit.execpath, " ", "\\ ")})[1]} - if luakit.verbose then table.insert(args, "-v") end - -- Relaunch without libunique bindings? - if luakit.nounique then table.insert(args, "-U") end - - -- Get new config path - local conf - if luakit.confpath ~= "/etc/xdg/luakit/rc.lua" and os.exists(luakit.confpath) then - conf = luakit.confpath - table.insert(args, string.format("-c %q", conf)) - end - - -- Check config has valid syntax - local cmd = table.concat(args, " ") - if luakit.spawn_sync(cmd .. " -k") ~= 0 then - return w:error("Cannot restart, syntax error in configuration file"..((conf and ": "..conf) or ".")) - end - - -- Save session. - local wins = {} - for _, w in pairs(window.bywidget) do table.insert(wins, w) end - session.save(wins) - - -- Replace current process with new luakit instance. - luakit.exec(cmd) - end, - - -- Intelligent open command which can detect a uri or search argument. - search_open = function (w, arg) - local lstring = lousy.util.string - local match, find = string.match, string.find - - -- Detect blank uris - if not arg or match(arg, "^%s*$") then return "about:blank" end - - -- Strip whitespace and split by whitespace into args table - local args = lstring.split(lstring.strip(arg)) - - -- Guess if first argument is an address, search engine, file - if #args == 1 then - local uri = args[1] - if uri == "about:blank" then return uri end - - -- Check if search engine name - if search_engines[uri] then - return string.format(search_engines[uri], "") - end - - -- Navigate if . or / in uri (I.e. domains, IP's, scheme://) - if find(uri, "%.") or find(uri, "/") then return uri end - - -- Navigate if this is a javascript-uri - if find(uri, "^javascript:") then return uri end - - -- Valid hostnames to check - local hosts = { "localhost" } - if globals.load_etc_hosts ~= false then - hosts = lousy.util.get_etc_hosts() - end - - -- Check hostnames - for _, h in pairs(hosts) do - if h == uri or match(uri, "^"..h..":%d+$") then return uri end - end - - -- Check for file in filesystem - if globals.check_filepath ~= false then - if lfs.attributes(uri) then return "file://" .. uri end - end - end - - -- Find search engine (or use search_engines.default) - local engine = "default" - if args[1] and search_engines[args[1]] then - engine = args[1] - table.remove(args, 1) - end - - -- URI encode search terms - local terms = luakit.uri_encode(table.concat(args, " ")) - return string.format(search_engines[engine], terms) - end, - - -- Increase (or decrease) the last found number in the current uri - inc_uri = function (w, arg) - local uri = string.gsub(w.view.uri, "(%d+)([^0-9]*)$", function (num, rest) - return string.format("%0"..#num.."d", tonumber(num) + (arg or 1)) .. rest - end) - return uri - end, - - -- Tab traversing functions - next_tab = function (w, n) - w.tabs:switch((((n or 1) + w.tabs:current() -1) % w.tabs:count()) + 1) - end, - - prev_tab = function (w, n) - w.tabs:switch(((w.tabs:current() - (n or 1) -1) % w.tabs:count()) + 1) - end, - - goto_tab = function (w, n) - if n and (n == -1 or n > 0) then - return w.tabs:switch((n <= w.tabs:count() and n) or -1) - end - end, - - -- For each tab, switches to that tab and calls the given function passing - -- it the view contained in the tab. - each_tab = function (w, fn) - for index = 1, w.tabs:count() do - w:goto_tab(index) - fn(w.tabs[index]) - end - end, - - -- If argument is form-active or root-active, emits signal. Ignores all - -- other signals. - emit_form_root_active_signal = function (w, s) - if s == "form-active" then - w.view:emit_signal("form-active") - elseif s == "root-active" then - w.view:emit_signal("root-active") - end - end, -} - --- Ordered list of class index functions. Other classes (E.g. webview) are able --- to add their own index functions to this list. -window.indexes = { - -- Find function in window.methods first - function (w, k) return window.methods[k] end -} - --- Create new window -function window.new(uris) - local w = window.build() - - -- Set window metatable - setmetatable(w, { - __index = function (_, k) - -- Check widget structure first - local v = rawget(w, k) - if v then return v end - -- Call each window index function - for _, index in ipairs(window.indexes) do - v = index(w, k) - if v then return v end - end - end, - }) - - -- Setup window widget for signals - lousy.signal.setup(w) - - -- Call window init functions - for _, func in pairs(window.init_funcs) do - func(w) - end - - -- Populate notebook with tabs - for _, uri in ipairs(uris or {}) do - w:new_tab(w:search_open(uri), false) - end - - -- Make sure something is loaded - if w.tabs:count() == 0 then - w:new_tab(w:search_open(globals.homepage), false) - end - - -- Set initial mode - w:set_mode() - - -- Show window - w.win:show() - - return w -end - --- vim: et:sw=4:ts=8:sts=4:tw=80 diff --git a/.muttrc b/.muttrc deleted file mode 100644 index 730d887..0000000 --- a/.muttrc +++ /dev/null @@ -1,49 +0,0 @@ -# A basic .muttrc for use with Gmail - -# Change the following six lines to match your Gmail account details -set imap_user = "yuv.adm@gmail.com" -set smtp_url = "smtp://yuv.adm@smtp.gmail.com:587/" -set from = "yuv.adm@gmail.com" -set realname = "Yuval Adam" - -# Change the following line to a different editor you prefer. -set editor = "vim" - -# Basic config, you can leave this as is -set folder = "imaps://imap.gmail.com:993" -set spoolfile = "+INBOX" -set imap_check_subscribed -set hostname = gmail.com -set mail_check = 120 -set timeout = 300 -set imap_keepalive = 300 -set postponed = "+[GMail]/Drafts" -set record = "+[GMail]/Sent Mail" -set header_cache=~/.mutt/cache/headers -set message_cachedir=~/.mutt/cache/bodies -set certificate_file=~/.mutt/certificates -set move = no -set include -set sort = 'threads' -set sort_aux = 'reverse-last-date-received' -set auto_tag = yes -ignore "Authentication-Results:" -ignore "DomainKey-Signature:" -ignore "DKIM-Signature:" -hdr_order Date From To Cc -alternative_order text/plain text/html * -auto_view text/html -bind editor <Tab> complete-query -bind editor ^T complete -bind editor <space> noop - -# Gmail-style keyboard shortcuts -macro index,pager y "<enter-command>unset trash\n <delete-message>" "Gmail archive message" -macro index,pager d "<enter-command>set trash=\"imaps://imap.googlemail.com/[GMail]/Bin\"\n <delete-message>" "Gmail delete message" -macro index,pager gi "<change-folder>=INBOX<enter>" "Go to inbox" -macro index,pager ga "<change-folder>=[Gmail]/All Mail<enter>" "Go to all mail" -macro index,pager gs "<change-folder>=[Gmail]/Starred<enter>" "Go to starred messages" -macro index,pager gd "<change-folder>=[Gmail]/Drafts<enter>" "Go to drafts" - -# Hebrew support -set display_filter=fribidi |
