Created
August 12, 2018 17:42
-
-
Save levex/8b015baa05f21ec32898878bec4fd350 to your computer and use it in GitHub Desktop.
Open manpages from Awesome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- | |
-- efine these functions somewhere in your rc.lua or utils.lua | |
-- | |
-- | |
function l_split(str, pat) | |
local t = {} -- NOTE: use {n = 0} in Lua-5.0 | |
local fpat = "(.-)" .. pat | |
local last_end = 1 | |
local s, e, cap = str:find(fpat, 1) | |
while s do | |
if s ~= 1 or cap ~= "" then | |
table.insert(t,cap) | |
end | |
last_end = e+1 | |
s, e, cap = str:find(fpat, last_end) | |
end | |
if last_end <= #str then | |
cap = str:sub(last_end) | |
table.insert(t, cap) | |
end | |
return t | |
end | |
function split_manpage(str) | |
return l_split(str,'[()]+') | |
end | |
-- | |
-- | |
-- Add the below blocks into your rc.lua | |
-- | |
-- | |
-- Create the manpage prompt | |
local manpageprompt_textbox = wibox.widget.textbox() | |
-- Create a shortcut function | |
local function run_manpage_prompt() | |
awful.prompt.run { | |
prompt = '<b>Manpage: </b>', | |
text = '', | |
bg_cursor = '#ff0000', | |
textbox = awful.screen.focused().mypromptbox.widget, | |
exe_callback = function(input) | |
if not input or #input == 0 then return end | |
local splut = split_manpage(input) | |
local mansect = splut[2] | |
local manpage = splut[1] | |
awful.spawn.with_shell(browser .. ' http://man7.org/linux/man-pages/man' .. mansect .. '/' .. manpage .. '.' .. mansect .. '.html') | |
end | |
} | |
end | |
-- | |
-- | |
-- Finally, define an awful key combination: | |
-- | |
-- | |
-- manpage prompt | |
awful.key({ "Control", altkey, modkey }, "m", run_manpage_prompt, | |
{description = "run manpage prompt", group = "launcher"}), | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment