]>
git.madduck.net Git - etc/awesome.git/commitdiff
madduck's git repository
Every one of the projects in this repository is available at the canonical
URL git://git.madduck.net/madduck/pub/<projectpath> — see
each project's metadata for the exact URL.
All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@ git. madduck. net .
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
SSH access, as well as push access can be individually
arranged .
If you use my repositories frequently, consider adding the following
snippet to ~/.gitconfig and using the third clone URL listed for each
project:
[url "git://git.madduck.net/madduck/"]
insteadOf = madduck:
summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (parent:
945f220 )
local capi = { timer = timer }
local io = { open = io.open,
local capi = { timer = timer }
local io = { open = io.open,
+ lines = io.lines,
+ popen = io.popen }
local rawget = rawget
-- Lain helper functions for internal use
local rawget = rawget
-- Lain helper functions for internal use
+-- {{{ Pipe operations
+
+-- read the full output of a pipe (command)
+function helpers.read_pipe(cmd)
+ local f = assert(io.popen(cmd))
+ local output = f:read("*all")
+ f:close()
+ return output
+end
+
+-- }}}
+
-- {{{ A map utility
helpers.map_table = {}
-- {{{ A map utility
helpers.map_table = {}
--]]
local newtimer = require("lain.helpers").newtimer
--]]
local newtimer = require("lain.helpers").newtimer
+local read_pipe = require("lain.helpers").read_pipe
local wibox = require("wibox")
local wibox = require("wibox")
-local io = { popen = io.popen }
local string = { match = string.match,
format = string.format }
local string = { match = string.match,
format = string.format }
alsa.widget = wibox.widget.textbox('')
function alsa.update()
alsa.widget = wibox.widget.textbox('')
function alsa.update()
- local f = assert(io.popen(string.format("%s get %s", alsa.cmd, alsa.channel)))
- local mixer = f:read("*all")
- f:close()
+ local mixer = read_pipe(string.format("%s get %s", alsa.cmd, alsa.channel))
--]]
local newtimer = require("lain.helpers").newtimer
--]]
local newtimer = require("lain.helpers").newtimer
+local read_pipe = require("lain.helpers").read_pipe
local awful = require("awful")
local beautiful = require("beautiful")
local naughty = require("naughty")
local awful = require("awful")
local beautiful = require("beautiful")
local naughty = require("naughty")
-local io = { popen = io.popen }
local math = { modf = math.modf }
local mouse = mouse
local string = { format = string.format,
local math = { modf = math.modf }
local mouse = mouse
local string = { format = string.format,
function alsabar.update()
-- Get mixer control contents
function alsabar.update()
-- Get mixer control contents
- local f = assert(io.popen(string.format("%s get %s", alsabar.cmd, alsabar.channel)))
- local mixer = f:read("*all")
- f:close()
+ local mixer = read_pipe(string.format("%s get %s", alsabar.cmd, alsabar.channel))
-- Capture mixer control state: [5%] ... ... [on]
local volu, mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
-- Capture mixer control state: [5%] ... ... [on]
local volu, mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
--]]
local newtimer = require("lain.helpers").newtimer
--]]
local newtimer = require("lain.helpers").newtimer
+local read_pipe = require("lain.helpers").read_pipe
+
local wibox = require("wibox")
local wibox = require("wibox")
-local io = { popen = io.popen }
local setmetatable = setmetatable
-- Basic template for custom widgets
local setmetatable = setmetatable
-- Basic template for custom widgets
base.widget = wibox.widget.textbox('')
function base.update()
base.widget = wibox.widget.textbox('')
function base.update()
- local f = assert(io.popen(cmd))
- output = f:read("*all")
- f:close()
+ output = read_pipe(cmd)
widget = base.widget
settings()
end
widget = base.widget
settings()
end
+--[[
+
+ Licensed under GNU General Public License v2
+ * (c) 2015, Dario Gjorgjevski
+
+--]]
+
local newtimer = require("lain.helpers").newtimer
local newtimer = require("lain.helpers").newtimer
+local read_pipe = require("lain.helpers").read_pipe
+
local wibox = require("wibox")
local string = { match = string.match }
local wibox = require("wibox")
local string = { match = string.match }
-local io = { popen = io.popen }
local setmetatable = setmetatable
local setmetatable = setmetatable
local kbdlayout = {}
kbdlayout.widget = wibox.widget.textbox('')
local kbdlayout = {}
kbdlayout.widget = wibox.widget.textbox('')
- local settings = args.settings or function () end
- local layouts = args.layouts
- local idx = 1
+ local layouts = args.layouts
+ local settings = args.settings or function () end
+ local add_us_secondary = args.add_us_secondary or true
+ local idx = 1
local function run_settings (layout, variant)
widget = kbdlayout.widget
local function run_settings (layout, variant)
widget = kbdlayout.widget
- kbdlayout_now = { layout=layout, variant=variant }
+ kbdlayout_now = { layout=string.match(layout, "[^,]+"), -- Make sure to match the primary layout only.
+ variant=variant }
settings()
end
function kbdlayout.update ()
settings()
end
function kbdlayout.update ()
- local file = assert(io.popen('setxkbmap -query'))
- local status = file:read('*all')
- file:close()
+ local status = read_pipe('setxkbmap -query')
- run_settings(string.match(status, "layout:%s*([^\n]*)%s* "),
- string.match(status, "variant:%s*([^\n]*)%s* "))
+ run_settings(string.match(status, "layout:%s*([^\n]*)"),
+ string.match(status, "variant:%s*([^\n]*)"))
end
function kbdlayout.set (i)
idx = ((i - 1) % #layouts) + 1 -- Make sure to wrap around as needed.
local to_execute = 'setxkbmap ' .. layouts[idx].layout
end
function kbdlayout.set (i)
idx = ((i - 1) % #layouts) + 1 -- Make sure to wrap around as needed.
local to_execute = 'setxkbmap ' .. layouts[idx].layout
+ if add_us_secondary then
+ to_execute = to_execute .. ",us"
+ end
+
if layouts[idx].variant then
to_execute = to_execute .. ' ' .. layouts[idx].variant
end
if layouts[idx].variant then
to_execute = to_execute .. ' ' .. layouts[idx].variant
end
function fs:show(t_out)
fs:hide()
function fs:show(t_out)
fs:hide()
- local f = io.popen(helpers.scripts_dir .. "dfs")
- ws = f:read("*all"):gsub("\n*$", "")
- f:close()
+ ws = helpers.read_pipe(helpers.scripts_dir .. "dfs"):gsub("\n*$", "")
if fs.followmouse then
fs.notification_preset.screen = mouse.screen
if fs.followmouse then
fs.notification_preset.screen = mouse.screen
- local f = io.popen(password)
- password = f:read("*all"):gsub("\n", "")
- f:close()
+ password = helpers.read_pipe(password):gsub("\n", "")
end
imap.widget = wibox.widget.textbox('')
end
imap.widget = wibox.widget.textbox('')
--]]
local newtimer = require("lain.helpers").newtimer
--]]
local newtimer = require("lain.helpers").newtimer
+local read_pipe = require("lain.helpers").read_pipe
local wibox = require("wibox")
local util = require("lain.util")
local wibox = require("wibox")
local util = require("lain.util")
-local io = { popen = io.popen }
local os = { getenv = os.getenv }
local pairs = pairs
local string = { len = string.len,
local os = { getenv = os.getenv }
local pairs = pairs
local string = { len = string.len,
-- match files that begin with a dot.
-- Afterwards the length of this string is the number of
-- new mails in that box.
-- match files that begin with a dot.
-- Afterwards the length of this string is the number of
-- new mails in that box.
- local np = io.popen ("find " .. line ..
+ local mailstring = read_pipe ("find " .. line ..
"/new -mindepth 1 -type f " ..
"-not -name '.*' -printf a")
"/new -mindepth 1 -type f " ..
"-not -name '.*' -printf a")
- local mailstring = np:read("*all")
-- Strip off leading mailpath.
local box = string.match(line, mailpath .. "/*([^/]+)")
-- Strip off leading mailpath.
local box = string.match(line, mailpath .. "/*([^/]+)")
table.sort(boxes)
newmail = "no mail"
table.sort(boxes)
newmail = "no mail"
- --Count the total number of mails irrespective of where it was found
+ -- Count the total number of mails irrespective of where it was found
total = 0
for box, number in pairs(boxes)
total = 0
for box, number in pairs(boxes)
local naughty = require("naughty")
local wibox = require("wibox")
local naughty = require("naughty")
local wibox = require("wibox")
-local io = { popen = io.popen }
local string = { format = string.format,
gsub = string.gsub,
match = string.match }
local string = { format = string.format,
gsub = string.gsub,
match = string.match }
}
function net.get_device()
}
function net.get_device()
- f = io.popen("ip link show | cut -d' ' -f2,9")
- ws = f:read("*all")
- f:close()
+ local ws = helpers.read_pipe("ip link show | cut -d' ' -f2,9")
ws = ws:match("%w+: UP") or ws:match("ppp%w+: UNKNOWN")
if ws ~= nil then
return ws:match("(%w+):")
ws = ws:match("%w+: UP") or ws:match("ppp%w+: UNKNOWN")
if ws ~= nil then
return ws:match("(%w+):")
--]]
local newtimer = require("lain.helpers").newtimer
--]]
local newtimer = require("lain.helpers").newtimer
+local read_pipe = require("lain.helpers").read_pipe
+
local async = require("lain.asyncshell")
local json = require("lain.util").dkjson
local lain_icons = require("lain.helpers").icons_dir
local async = require("lain.asyncshell")
local json = require("lain.util").dkjson
local lain_icons = require("lain.helpers").icons_dir
local naughty = require("naughty")
local wibox = require("wibox")
local naughty = require("naughty")
local wibox = require("wibox")
if not err and weather_now ~= nil and tonumber(weather_now["cod"]) == 200 then
weather.notification_text = ''
for i = 1, weather_now["cnt"] do
if not err and weather_now ~= nil and tonumber(weather_now["cod"]) == 200 then
weather.notification_text = ''
for i = 1, weather_now["cnt"] do
- local f = assert(io.popen(string.format(date_cmd, weather_now["list"][i]["dt"])))
- day = string.gsub(f:read("*all"), "\n", "")
- f:close()
+ day = string.gsub(read_pipe(string.format(date_cmd, weather_now["list"][i]["dt"])), "\n", "")
tmin = math.floor(weather_now["list"][i]["temp"]["min"])
tmax = math.floor(weather_now["list"][i]["temp"]["max"])
tmin = math.floor(weather_now["list"][i]["temp"]["min"])
tmax = math.floor(weather_now["list"][i]["temp"]["max"])