From 49c05a4f1b369675883d8037312a26ead4893a5c Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 21 Sep 2017 16:14:31 -0300 Subject: Major update compatible with current upstream --- config.dot/luakit.link/binds.lua | 387 ---------------------------------- config.dot/luakit.link/globals.lua | 95 --------- config.dot/luakit.link/keys.lua | 86 ++++++++ config.dot/luakit.link/rc.lua | 29 ++- config.dot/luakit.link/sessions.lua | 69 +++++++ config.dot/luakit.link/sessman | 1 - config.dot/luakit.link/userprefs.lua | 19 ++ config.dot/luakit.link/webview.lua | 389 ----------------------------------- 8 files changed, 192 insertions(+), 883 deletions(-) delete mode 100644 config.dot/luakit.link/binds.lua delete mode 100644 config.dot/luakit.link/globals.lua create mode 100644 config.dot/luakit.link/keys.lua create mode 100644 config.dot/luakit.link/sessions.lua delete mode 120000 config.dot/luakit.link/sessman create mode 100644 config.dot/luakit.link/userprefs.lua delete mode 100644 config.dot/luakit.link/webview.lua diff --git a/config.dot/luakit.link/binds.lua b/config.dot/luakit.link/binds.lua deleted file mode 100644 index b2b10d4..0000000 --- a/config.dot/luakit.link/binds.lua +++ /dev/null @@ -1,387 +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 more, less = "+"..scroll_step.."px", "-"..scroll_step.."px" -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", function (w) w:set_mode() end), - key({"Control"}, "[", function (w) w:set_mode() end), - - -- Mouse bindings - but({}, 8, function (w) w:back() end), - but({}, 9, function (w) w:forward() end), - - -- Open link in new tab or navigate to selection - but({}, 2, 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, function (w, m) - local uri = w.view.hovered_uri - if uri then - w:new_tab(uri, false) - end - end), - - -- Zoom binds - but({"Control"}, 4, function (w, m) w:zoom_in() end), - but({"Control"}, 5, function (w, m) w:zoom_out() end), - - -- Horizontal mouse scroll binds - but({"Shift"}, 4, function (w, m) w:scroll{ x = less } end), - but({"Shift"}, 5, function (w, m) w:scroll{ x = more } 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(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", function (w) w:set_mode("insert") end), - key({}, ":", function (w) w:set_mode("command") end), - - -- Scrolling - key({}, "j", function (w) w:scroll{ y = more } end), - key({}, "k", function (w) w:scroll{ y = less } end), - key({}, "h", function (w) w:scroll{ x = less } end), - key({}, "l", function (w) w:scroll{ x = more } end), - key({}, "^", function (w) w:scroll{ x = "0%" } end), - key({}, "$", function (w) w:scroll{ x = "100%" } end), - key({"Control"}, "e", function (w) w:scroll{ y = more } end), - key({"Control"}, "y", function (w) w:scroll{ y = less } end), - key({"Control"}, "d", function (w) w:scroll{ y = "+0.5p" } end), - key({"Control"}, "u", function (w) w:scroll{ y = "-0.5p" } end), - key({"Control"}, "f", function (w) w:scroll{ y = "+1.0p" } end), - key({"Control"}, "b", function (w) w:scroll{ y = "-1.0p" } end), - key({}, "space", function (w) w:scroll{ y = "+1.0p" } end), - key({"Shift"}, "space", function (w) w:scroll{ y = "-1.0p" } end), - key({}, "BackSpace", function (w) w:scroll{ y = "-1.0p" } end), - - -- Specific scroll - buf("^gg$", function (w, b, m) w:scroll{ y = m.count.."%" } end, {count = 0}), - buf("^G$", function (w, b, m) w:scroll{ y = m.count.."%" } end, {count = 100}), - - -- Traditional scrolling commands - key({}, "Down", function (w) w:scroll{ y = more } end), - key({}, "Up", function (w) w:scroll{ y = less } end), - key({}, "Left", function (w) w:scroll{ x = less } end), - key({}, "Right", function (w) w:scroll{ x = more } end), - key({}, "Page_Down", function (w) w:scroll{ y = string.format("+%.1fp", 1.0) } end), - key({}, "Page_Up", function (w) w:scroll{ y = string.format("-%.1fp", 1.0) } end), - key({}, "Home", function (w) w:scroll{ y = "0%" } end), - key({}, "End", function (w) w:scroll{ y = "100%" } end), - key({}, "$", function (w) w:scroll{ x = "100%" } end), - key({}, "0", function (w, m) - if not m.count then w:scroll{ y = "0%" } else return false end - end), - - -- Zooming - key({}, "+", function (w, m) w:zoom_in(zoom_step * m.count) end, {count=1}), - key({}, "-", function (w, m) w:zoom_out(zoom_step * m.count) end, {count=1}), - key({}, "=", function (w, m) w:zoom_set() end), - buf("^z[iI]$", function (w, b, m) w:zoom_in(zoom_step * m.count, b == "zI") end, {count=1}), - buf("^z[oO]$", 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]$", function (w, b, m) w:zoom_set(m.count/100, b == "zZ") end, {count=100}), - - -- Fullscreen - key({}, "F11", function (w) - w.win.fullscreen = not w.win.fullscreen - end), - - -- Clipboard - key({}, "p", function (w) - local uri = luakit.selection.primary - if uri then w:navigate(w:search_open(uri)) else w:error("Empty selection.") end - end), - key({}, "P", function (w, m) - local uri = luakit.selection.primary - if not uri then w:error("Empty selection.") return end - for i = 1, m.count do w:new_tab(w:search_open(uri)) end - end, {count = 1}), - - -- Yanking - buf("^yy$", function (w) - local uri = string.gsub(w.view.uri or "", " ", "%%20") - luakit.selection.primary = uri - luakit.selection.clipboard = uri - w:notify("Yanked uri: " .. uri) - end), - - buf("^yt$", function (w) - local title = w.view.title - luakit.selection.primary = title - luakit.selection.clipboard = uri - w:notify("Yanked title: " .. title) - end), - - -- Yank URL and title as a Markdown link - buf("^ym$", function (w) - local title = w.view.title - local uri = string.gsub(w.view.uri or "", " ", "%%20") - local link = '[' .. title .. '](' .. uri .. ')' - luakit.selection.primary = link - luakit.selection.clipboard = link - w:notify("Yanked link: " .. link) - end), - - -- Yank URL and title as a reStructuredText link - buf("^yr$", function (w) - local title = w.view.title - local uri = string.gsub(w.view.uri or "", " ", "%%20") - local link = '`' .. title .. '` <' .. uri .. '>`_' - luakit.selection.primary = link - luakit.selection.clipboard = link - w:notify("Yanked link: " .. link) - end), - - -- Yank URL and title as a Trac link - buf("^yc$", function (w) - local title = w.view.title - local uri = string.gsub(w.view.uri or "", " ", "%%20") - local link = '[' .. uri .. ' ' .. title .. ']' - luakit.selection.primary = link - luakit.selection.clipboard = link - w:notify("Yanked link: " .. link) - end), - - -- Yank URL and title as an HTML link - buf("^yh$", function (w) - local title = w.view.title - local uri = string.gsub(w.view.uri or "", " ", "%%20") - local link = '' .. title .. '' - luakit.selection.primary = link - luakit.selection.clipboard = link - w:notify("Yanked link: " .. link) - end), - - -- Yank URL and title as a shareable link - buf("^ys$", function (w) - local title = w.view.title - local uri = string.gsub(w.view.uri or "", " ", "%%20") - local link = title .. ' - ' .. uri - luakit.selection.primary = link - luakit.selection.clipboard = link - w:notify("Yanked link: " .. link) - end), - - -- Commands - key({"Control"}, "a", function (w) w:navigate(w:inc_uri(1)) end), - key({"Control"}, "x", function (w) w:navigate(w:inc_uri(-1)) end), - buf("^o$", function (w, c) w:enter_cmd(":open ") end), - buf("^t$", function (w, c) w:enter_cmd(":tabopen ") end), - buf("^w$", function (w, c) w:enter_cmd(":winopen ") end), - buf("^O$", function (w, c) w:enter_cmd(":open " .. (w.view.uri or "")) end), - buf("^T$", function (w, c) w:enter_cmd(":tabopen " .. (w.view.uri or "")) end), - buf("^W$", function (w, c) w:enter_cmd(":winopen " .. (w.view.uri or "")) end), - buf("^,g$", function (w, c) w:enter_cmd(":open google ") end), - buf("^,d$", function (w, c) w:enter_cmd(":open duckduckgo ") end), - buf("^,h$", function (w, c) w:enter_cmd(":open duckduckgo !hackage " -) end), - buf("^,n$", function (w, c) w:enter_cmd(":open netflix " -) end), - - -- History - key({}, "H", function (w, m) w:back(m.count) end), - key({}, "L", function (w, m) w:forward(m.count) end), - key({}, "b", function (w, m) w:back(m.count) end), - key({}, "XF86Back", function (w, m) w:back(m.count) end), - key({}, "XF86Forward", function (w, m) w:forward(m.count) end), - key({"Control"}, "o", function (w, m) w:back(m.count) end), - key({"Control"}, "i", function (w, m) w:forward(m.count) end), - - -- Tab - key({"Control"}, "Page_Up", function (w) w:prev_tab() end), - key({"Control"}, "Page_Down", function (w) w:next_tab() end), - key({"Control"}, "Tab", function (w) w:next_tab() end), - key({"Shift","Control"}, "Tab", function (w) w:prev_tab() end), - buf("^gT$", function (w, b, m) w:prev_tab(m.count) end, {count=1}), - buf("^gt$", function (w, b, m) if not w:goto_tab(m.count) then w:next_tab() end end, {count=0}), - - key({"Control"}, "t", function (w) w:new_tab(globals.homepage) end), - key({"Control"}, "w", function (w) w:close_tab() end), - key({}, "d", function (w, m) for i=1,m.count do w:close_tab() end end, {count=1}), - - key({}, "<", function (w, m) w.tabs:reorder(w.view, w.tabs:current() - m.count) end, {count=1}), - key({}, ">", function (w, m) w.tabs:reorder(w.view, (w.tabs:current() + m.count) % w.tabs:count()) end, {count=1}), - key({"Mod1"}, "Page_Up", function (w, m) w.tabs:reorder(w.view, w.tabs:current() - m.count) end, {count=1}), - key({"Mod1"}, "Page_Down", function (w, m) w.tabs:reorder(w.view, (w.tabs:current() + m.count) % w.tabs:count()) end, {count=1}), - - buf("^gH$", function (w, b, m) for i=1,m.count do w:new_tab(globals.homepage) end end, {count=1}), - buf("^gh$", function (w) w:navigate(globals.homepage) end), - - -- Open tab from current tab history - buf("^gy$", function (w) w:new_tab(w.view.history or "") end), - - key({}, "r", function (w) w:reload() end), - key({}, "R", function (w) w:reload(true) end), - key({"Control"}, "c", function (w) w:stop() end), - - -- Config reloading - key({"Control", "Shift"}, "R", function (w) w:restart() end), - - -- Window - buf("^ZZ$", function (w) w:save_session() w:close_win() end), - buf("^ZQ$", function (w) w:close_win() end), - buf("^D$", function (w) w:close_win() end), - - -- Enter passthrough mode - key({"Control"}, "z", function (w) w:set_mode("passthrough") end), - - -- Quit shortcut - key({}, "q", function (w) w:save_session() w:close_win() end), -}) - -add_binds("insert", { - key({"Control"}, "z", function (w) w:set_mode("passthrough") end), -}) - -add_binds({"command", "search"}, { - key({"Shift"}, "Insert", function (w) w:insert_cmd(luakit.selection.primary) end), - key({"Control"}, "w", function (w) w:del_word() end), - key({"Control"}, "u", function (w) w:del_line() end), - key({"Control"}, "h", function (w) w:del_backward_char() end), - key({"Control"}, "d", function (w) w:del_forward_char() end), - key({"Control"}, "a", function (w) w:beg_line() end), - key({"Control"}, "e", function (w) w:end_line() end), - key({"Control"}, "f", function (w) w:forward_char() end), - key({"Control"}, "b", function (w) w:backward_char() end), - key({"Mod1"}, "f", function (w) w:forward_word() end), - key({"Mod1"}, "b", function (w) w:backward_word() end), -}) - --- Switching tabs with Mod1+{1,2,3,...} -mod1binds = {} -for i=1,10 do - table.insert(mod1binds, - key({"Mod1"}, tostring(i % 10), 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({ - -- Detect bangs (I.e. ":command! ") - buf("^%S+!", 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({command, alias1, ...}, function (w, arg, opts) .. end, opts), - -- cmd("co[mmand]", function (w, arg, opts) .. end, opts), - cmd("c[lose]", function (w) w:close_tab() end), - cmd("print", function (w) w:eval_js("print()", "rc.lua") end), - cmd("reload", function (w) w:reload() end), - cmd("restart", function (w) w:restart() end), - cmd("write", function (w) w:save_session() end), - cmd("noh[lsearch]", function (w) w:clear_search() end), - - cmd("back", function (w, a) w:back(tonumber(a) or 1) end), - cmd("f[orward]", function (w, a) w:forward(tonumber(a) or 1) end), - cmd("inc[rease]", function (w, a) w:navigate(w:inc_uri(tonumber(a) or 1)) end), - cmd("o[pen]", function (w, a) w:navigate(w:search_open(a)) end), - cmd("t[abopen]", function (w, a) w:new_tab(w:search_open(a)) end), - cmd("w[inopen]", function (w, a) window.new{w:search_open(a)} end), - cmd({"javascript", "js"}, function (w, a) w:eval_js(a, "javascript") end), - - cmd("q[uit]", function (w, a, o) w:close_win(o.bang) end), - cmd({"viewsource", "vs" }, function (w, a, o) w:toggle_source(not o.bang and true or nil) end), - cmd({"writequit", "wq"}, function (w, a, o) w:save_session() w:close_win(o.bang) end), - - cmd("lua", 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", 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:eval_js("document.documentElement.outerHTML", "dump"), "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.dot/luakit.link/globals.lua b/config.dot/luakit.link/globals.lua deleted file mode 100644 index eb51a3e..0000000 --- a/config.dot/luakit.link/globals.lua +++ /dev/null @@ -1,95 +0,0 @@ --- Environment -homedir = os.getenv("HOME") - --- Global variables for luakit -globals = { - -- homepage = homedir .. "/html/index.html", - -- homepage = "http://luakit.org/", - -- homepage = "http://github.com/mason-larobina/luakit", - scroll_step = 40, - zoom_step = 0.1, - max_cmd_history = 100, - max_srch_history = 100, - -- proxy must now be set through proxy command; environment variable is broken - default_window_size = "800x600", - term = "x-terminal-emulator", - - -- 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 - --- Stop navigation sites with invalid or expired ssl certificates -soup.ssl_strict = true - --- Set cookie acceptance policy --- Valid values are always, never or no_third_party -soup.accept_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 = { - luakit = "http://luakit.org/search/index/luakit?q=%s", - imdb = "http://imdb.com/find?s=all&q=%s", - netflix = "http://dvd.netflix.com/Search?v1=%s", - google = "https://google.com/search?q=%s", - duck = "https://duckduckgo.com/?q=%s&t=debian", - wikipedia = "https://en.wikipedia.org/wiki/Special:Search?search=%s", - debbugs = "https://bugs.debian.org/%s", - sourceforge = "https://sf.net/search/?words=%s", - debian = "https://packages.debian.org/search?keywords=%s", - searx = "https://searx.org/?q=%s" -} - --- Set fallback search engine -search_engines.default = search_engines.duck --- Use this instead to disable auto-searching ---search_engines.default = "%s" - --- Per-domain webview properties --- See http://webkitgtk.org/reference/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.dot/luakit.link/keys.lua b/config.dot/luakit.link/keys.lua new file mode 100644 index 0000000..d1f16c7 --- /dev/null +++ b/config.dot/luakit.link/keys.lua @@ -0,0 +1,86 @@ +-- +-- Custom keybindings +-- + +-- Requirements +local modes = require "modes" +local window = require "window" + +-- Remove some default bindings +modes.remove_binds("normal", { "y" }) + +-- Add custom binds +modes.add_binds("normal", { + { "h", "New blank tab", function (w) + w:new_tab('luakit://newtab') + end}, +}) + +-- Add custom Yank bindings +modes.add_binds("normal", { + -- Yank URL + { "^yy$", function (w) + local uri = string.gsub(w.view.uri or "", " ", "%%20") + luakit.selection.primary = uri + luakit.selection.clipboard = uri + w:notify("Yanked uri: " .. uri) + end}, + + -- Yank title + { "^yt$", function (w) + local title = w.view.title + luakit.selection.primary = title + luakit.selection.clipboard = uri + w:notify("Yanked title: " .. title) + end}, + + -- Yank URL and title as a Markdown link + { "^ym$", function (w) + local title = w.view.title + local uri = string.gsub(w.view.uri or "", " ", "%%20") + local link = '[' .. title .. '](' .. uri .. ')' + luakit.selection.primary = link + luakit.selection.clipboard = link + w:notify("Yanked as markdown link: " .. link) + end}, + + -- Yank URL and title as a reStructuredText link + { "^yr$", function (w) + local title = w.view.title + local uri = string.gsub(w.view.uri or "", " ", "%%20") + local link = '`' .. title .. '` <' .. uri .. '>`_' + luakit.selection.primary = link + luakit.selection.clipboard = link + w:notify("Yanked as reStructuredText link: " .. link) + end}, + + -- Yank URL and title as a Trac link + { "^yc$", function (w) + local title = w.view.title + local uri = string.gsub(w.view.uri or "", " ", "%%20") + local link = '[' .. uri .. ' ' .. title .. ']' + luakit.selection.primary = link + luakit.selection.clipboard = link + w:notify("Yanked as Trac link: " .. link) + end}, + + -- Yank URL and title as an HTML link + { "^yh$", function (w) + local title = w.view.title + local uri = string.gsub(w.view.uri or "", " ", "%%20") + local link = '' .. title .. '' + luakit.selection.primary = link + luakit.selection.clipboard = link + w:notify("Yanked as HTML link: " .. link) + end}, + + -- Yank URL and title as a shareable link + { "^ys$", function (w) + local title = w.view.title + local uri = string.gsub(w.view.uri or "", " ", "%%20") + local link = title .. ' - ' .. uri + luakit.selection.primary = link + luakit.selection.clipboard = link + w:notify("Yanked as shareable link: " .. link) + end}, +}) diff --git a/config.dot/luakit.link/rc.lua b/config.dot/luakit.link/rc.lua index 1014f36..b04d775 100644 --- a/config.dot/luakit.link/rc.lua +++ b/config.dot/luakit.link/rc.lua @@ -163,22 +163,29 @@ local tab_favicons = require "tab_favicons" -- Add :view-source command local view_source = require "view_source" --- Load sessman ---local sessman = require "sessman" +-- Load sessions +local sessions = require "sessions" + +-- Custom keys +local keys = require "keys" + +-- Globals +local userprefs = require "userprefs" ----------------------------- -- End user script loading -- ----------------------------- -- Restore last saved session -local w = (not luakit.nounique) and (session and session.restore()) -if w then - for i, uri in ipairs(uris) do - w:new_tab(uri, { switch = i == 1 }) - end -else - -- Or open new window - window.new(uris) -end +--local w = (not luakit.nounique) and (session and session.restore()) +--if w then +-- for i, uri in ipairs(uris) do +-- w:new_tab(uri, { switch = i == 1 }) +-- end +--else +-- -- Or open new window +-- window.new(uris) +--end +window.new(uris) -- vim: et:sw=4:ts=8:sts=4:tw=80 diff --git a/config.dot/luakit.link/sessions.lua b/config.dot/luakit.link/sessions.lua new file mode 100644 index 0000000..7daa6ed --- /dev/null +++ b/config.dot/luakit.link/sessions.lua @@ -0,0 +1,69 @@ +-- +-- Session management for luakit +-- By Silvio Rhatto +-- Using https://luakit.github.io/docs/modules/session.html +-- Inspired by https://github.com/IsoLinearCHiP/luakit-sessman +-- + +-- Requirements +local lfs = lfs +local info = info +local window = require "window" +local modes = require "modes" +local session = require "session" + +-- Base folder +function basedir() + return os.getenv("XDG_DATA_HOME") or os.getenv("HOME") .. "/.local/share" +end + +-- The directory where sessions are stored +local path = basedir() .. "/luakit/sessions/" +if not lfs.attributes(path) then lfs.mkdir(path) end + +-- Commands +modes.add_cmds({ + { ":sessionload, :sload, :loadsession, :openssession", "Load a session", function (w, a) + local file = path .. a.arg + session.session_file = file + + session.restore(false) + w:close_win() + end}, + { ":sessionsave, :ssave, :savesession", "Save a session", function (w, a) + local file = path .. a.arg + session.session_file = file + + session.save(file) + msg.info("Saved session at " .. file) + end}, + { ":sessionremove, :srm, :removesession", "Remove a session", function (w, a) + local file = path .. a.arg + session.session_file = nil + + local deleted = session.load(true, file) + end}, + { ":sessions", "Session manager", function (w) + local files = '' + + for file in lfs.dir(path) do + if not (file == "." or file == "..") then + files = files .. ' ' .. file + end + end + + w:notify("Available sessions:" .. files) + end }, +}) + +-- Bindings +modes.add_binds("normal", { + -- Quit and save session binding + { "^q$", "Quit and save current session", function (w) + session.save() + + for _, ww in pairs(window.bywidget) do + ww:close_win(true) + end + end}, +}) diff --git a/config.dot/luakit.link/sessman b/config.dot/luakit.link/sessman deleted file mode 120000 index ed64fbe..0000000 --- a/config.dot/luakit.link/sessman +++ /dev/null @@ -1 +0,0 @@ -contrib/sessman/sessman \ No newline at end of file diff --git a/config.dot/luakit.link/userprefs.lua b/config.dot/luakit.link/userprefs.lua new file mode 100644 index 0000000..35c865c --- /dev/null +++ b/config.dot/luakit.link/userprefs.lua @@ -0,0 +1,19 @@ +-- User preferences +-- See https://github.com/luakit/luakit/issues/468 + +-- Requirements +local settings = require "settings" + +-- Homepage +settings.window.home_page = "luakit://newtab" + +-- Search engines +settings.window.search_engines.imdb = "http://imdb.com/find?s=all&q=%s" +settings.window.search_engines.google = "https://google.com/search?q=%s" +settings.window.search_engines.duck = "https://duckduckgo.com/?q=%s&t=debian" +settings.window.search_engines.wikipedia = "https://en.wikipedia.org/wiki/Special:Search?search=%s" +settings.window.search_engines.debbugs = "https://bugs.debian.org/%s" +settings.window.search_engines.sourceforge = "https://sf.net/search/?words=%s" +settings.window.search_engines.debian = "https://packages.debian.org/search?keywords=%s" +settings.window.search_engines.searx = "https://searx.org/?q=%s" +settings.window.search_engines.default = settings.window.search_engines.duck diff --git a/config.dot/luakit.link/webview.lua b/config.dot/luakit.link/webview.lua deleted file mode 100644 index 0174151..0000000 --- a/config.dot/luakit.link/webview.lua +++ /dev/null @@ -1,389 +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) - -- 'link' contains the download link - -- 'reason' contains the reason of the request (i.e. "link-clicked") - -- return TRUE to handle the request by yourself or FALSE to proceed - -- with default behaviour - view:add_signal("new-window-decision", function (v, uri, reason) - info("New window decision: %s (%s)", 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 = { - stop = function (view) view:stop() end, - - -- 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, - - -- Evaluate javascript code and return string result - -- The frame argument can be any of the following: - -- * true to evaluate on the focused frame - -- * false or nothing to evaluate on the main frame - -- * a frame object to evaluate on the given frame - eval_js = function (view, w, script, file, frame) - return view:eval_js(script, file or "(inline)", frame) - end, - - -- Evaluate javascript code from file and return string result - -- The frame argument can be any of the following: - -- * true to evaluate on the focused frame - -- * false or nothing to evaluate on the main frame - -- * a frame object to evaluate on the given frame - eval_js_from_file = function (view, w, file, frame) - local fh, err = io.open(file) - if not fh then return error(err) end - local script = fh:read("*a") - fh:close() - return view:eval_js(script, file, frame) - 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, -} - -webview.scroll_parse_funcs = { - -- Abs "100px" - ["^(%d+)px$"] = function (_, _, px) return px end, - - -- Rel "+/-100px" - ["^([-+]%d+)px$"] = function (s, axis, px) return s[axis] + px end, - - -- Abs "10%" - ["^(%d+)%%$"] = function (s, axis, pc) - return math.ceil(s[axis.."max"] * (pc / 100)) - end, - - -- Rel "+/-10%" - ["^([-+]%d+)%%$"] = function (s, axis, pc) - return s[axis] + math.ceil(s[axis.."max"] * (pc / 100)) - end, - - -- Abs "10p" (pages) - ["^(%d+%.?%d*)p$"] = function (s, axis, p) - return math.ceil(s[axis.."page_size"] * p) - end, - - -- Rel "+10p" (pages) - ["^([-+]%d+[.,]?%d*)p$"] = function (s, axis, p) - return s[axis] + math.ceil(s[axis.."page_size"] * p) - end, -} - -function webview.methods.scroll(view, w, new) - local scroll = view.scroll - for axis, val in pairs{ x = new.x, y = new.y } do - if type(val) == "number" then - scroll[axis] = val - else - for pat, func in pairs(webview.scroll_parse_funcs) do - local n = string.match(val, pat) - if n then scroll[axis] = func(scroll, axis, tonumber(n)) end - end - end - end -end - -function webview.new(w) - local view = widget{type = "webview"} - - view.show_scrollbars = 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 -- cgit v1.2.3