General cleanup
This commit is contained in:
parent
4f3599db00
commit
2a5126f4f0
1
bat.lua
1
bat.lua
|
@ -22,7 +22,6 @@ module("vicious.bat")
|
|||
|
||||
-- {{{ Battery widget type
|
||||
local function worker(format, batid)
|
||||
-- Initialise tables
|
||||
local battery_state = {
|
||||
["full"] = "↯",
|
||||
["unknown"] = "⌁",
|
||||
|
|
|
@ -16,7 +16,6 @@ module("vicious.batat")
|
|||
|
||||
-- {{{ Battery widget type
|
||||
local function worker(format)
|
||||
-- Initialise tables
|
||||
local battery_info = {}
|
||||
local battery_state = {
|
||||
["full"] = "↯",
|
||||
|
@ -29,7 +28,6 @@ local function worker(format)
|
|||
-- Get data from acpitool
|
||||
local f = io.popen("acpitool -b")
|
||||
|
||||
-- Format data
|
||||
for line in f:lines() do
|
||||
-- Check if the battery is present
|
||||
if line:match("^[%s]+Battery.*") then
|
||||
|
|
2
cpu.lua
2
cpu.lua
|
@ -27,7 +27,6 @@ local function worker(format)
|
|||
local f = io.open("/proc/stat")
|
||||
local cpu_lines = {}
|
||||
|
||||
-- Format data
|
||||
for line in f:lines() do
|
||||
if line:find("^cpu") then
|
||||
if #cpu_lines < 1 then cpuid = 1
|
||||
|
@ -52,7 +51,6 @@ local function worker(format)
|
|||
table.insert(cpu_usage, 0)
|
||||
end
|
||||
|
||||
-- Setup tables
|
||||
local total_new = {}
|
||||
local active_new = {}
|
||||
local diff_total = {}
|
||||
|
|
|
@ -19,7 +19,6 @@ module("vicious.cpufreq")
|
|||
|
||||
-- {{{ CPU frequency widget type
|
||||
local function worker(format, cpuid)
|
||||
-- Initialise tables
|
||||
--local governor_state = {
|
||||
-- ["ondemand"] = "↯",
|
||||
-- ["powersave"] = "⌁",
|
||||
|
|
|
@ -16,25 +16,21 @@ module("vicious.cpuinf")
|
|||
|
||||
-- {{{ CPU Information widget type
|
||||
local function worker(format)
|
||||
-- Initialise variables
|
||||
cpu_id = nil
|
||||
|
||||
-- Get cpuinfo
|
||||
local f = io.open("/proc/cpuinfo")
|
||||
local cpu_info = {}
|
||||
|
||||
-- Get data
|
||||
for line in f:lines() do
|
||||
if line:match("^processor.*") then
|
||||
cpu_id = line:match("([%d]+)")
|
||||
elseif line:match("^cpu MHz.*") then
|
||||
local cpu_speed = line:match("([%d]+)%.")
|
||||
-- Store values
|
||||
cpu_info["{"..cpu_id.." mhz}"] = cpu_speed
|
||||
cpu_info["{"..cpu_id.." ghz}"] = tonumber(cpu_speed) / 1000
|
||||
elseif line:match("^cache size.*") then
|
||||
local cpu_cache = line:match("([%d]+)[%s]KB")
|
||||
-- Store values
|
||||
cpu_info["{"..cpu_id.." kb}"] = cpu_cache
|
||||
cpu_info["{"..cpu_id.." mb}"] = tonumber(cpu_cache) / 1024
|
||||
end
|
||||
|
|
1
date.lua
1
date.lua
|
@ -15,7 +15,6 @@ module("vicious.date")
|
|||
|
||||
-- {{{ Date widget type
|
||||
local function worker(format)
|
||||
-- Get format
|
||||
if format == nil then
|
||||
return os.date()
|
||||
else
|
||||
|
|
2
dio.lua
2
dio.lua
|
@ -27,7 +27,6 @@ local function worker(format, disk)
|
|||
local f = io.open("/proc/diskstats")
|
||||
local disk_lines = {}
|
||||
|
||||
-- Format data
|
||||
for line in f:lines() do
|
||||
if line:match("("..disk..")%s") then
|
||||
-- Todo: find a way to do this
|
||||
|
@ -52,7 +51,6 @@ local function worker(format, disk)
|
|||
table.insert(disk_total, 0)
|
||||
end
|
||||
|
||||
-- Setup tables
|
||||
local diff_total = {}
|
||||
|
||||
for i, v in ipairs(disk_lines) do
|
||||
|
|
3
fs.lua
3
fs.lua
|
@ -20,11 +20,10 @@ local function worker(format)
|
|||
local f = io.popen("LANG=C df -hP")
|
||||
local fs_info = {}
|
||||
|
||||
-- Format data
|
||||
for line in f:lines() do
|
||||
if not line:match("^Filesystem.*") then
|
||||
-- Format helper can't deal with matrices, so don't setup a
|
||||
-- table for each mount point with gmatch
|
||||
-- table for each mount point, with gmatch
|
||||
local size, used, avail, usep, mount =
|
||||
-- Instead match all at once, including network file systems
|
||||
line:match("^[%w%p]+[%s]+([%d%.]+)[%a]?[%s]+([%d%.]+)[%a]?[%s]+([%d%.]+)[%a]?[%s]+([%d]+)%%[%s]+([%w%p]+)$")
|
||||
|
|
|
@ -16,7 +16,6 @@ module("vicious.gmail")
|
|||
|
||||
-- {{{ Gmail widget type
|
||||
local function worker(format, login)
|
||||
-- Initialise tables
|
||||
local mail = {
|
||||
["{count}"] = "0",
|
||||
["{subject}"] = "N/A"
|
||||
|
|
|
@ -22,7 +22,6 @@ local function worker(format, port)
|
|||
local f = io.popen("curl --connect-timeout 1 -fsm 3 telnet://127.0.0.1:" .. port)
|
||||
local hdd_temp = {}
|
||||
|
||||
-- Get temperature data
|
||||
for line in f:lines() do
|
||||
local disk, temp = line:match("|([%/%a]+)|.*|([%d]+)|[CF]+|")
|
||||
|
||||
|
|
39
init.lua
39
init.lua
|
@ -1,16 +1,13 @@
|
|||
----------------------------------------------------------------
|
||||
--------------------------------------------------------------
|
||||
-- Vicious widgets for the awesome window manager
|
||||
--
|
||||
--------------------------------------------------------------
|
||||
-- Licensed under the GNU General Public License version 2
|
||||
-- * Copyright (C) 2009 Adrian C. <anrxc_sysphere_org>
|
||||
--
|
||||
-- To view a human-readable summary of the license, visit:
|
||||
-- * http://creativecommons.org/licenses/GPL/2.0/
|
||||
----------------------------------------------------------------
|
||||
--------------------------------------------------------------
|
||||
-- Derived from Wicked, by Lucas de Vries <lucas_glacicle_com>
|
||||
-- * http://git.glacicle.com/cgit.cgi/wicked
|
||||
-- * Wicked is licensed under the WTFPL v2
|
||||
----------------------------------------------------------------
|
||||
--------------------------------------------------------------
|
||||
|
||||
-- {{{ Grab environment
|
||||
require("awful")
|
||||
|
@ -63,7 +60,7 @@ require("vicious.date")
|
|||
module("vicious")
|
||||
|
||||
|
||||
-- {{{ Initialise variables
|
||||
-- {{{ Initialise tables
|
||||
local timers = {}
|
||||
local registered = {}
|
||||
local widget_cache = {}
|
||||
|
@ -88,7 +85,7 @@ end
|
|||
-- }}}
|
||||
|
||||
-- {{{ Main functions
|
||||
-- {{{ Register widget
|
||||
-- {{{ Register a widget
|
||||
function register(widget, wtype, format, timer, warg)
|
||||
local reg = {}
|
||||
local widget = widget
|
||||
|
@ -110,10 +107,10 @@ function register(widget, wtype, format, timer, warg)
|
|||
reg.timer = 1
|
||||
end
|
||||
|
||||
-- Register reg object
|
||||
-- Register a reg object
|
||||
regregister(reg)
|
||||
|
||||
-- Return reg object for reuse
|
||||
-- Return a reg object for reuse
|
||||
return reg
|
||||
end
|
||||
-- }}}
|
||||
|
@ -121,12 +118,11 @@ end
|
|||
-- {{{ Register from reg object
|
||||
function regregister(reg)
|
||||
if not reg.running then
|
||||
-- Put widget in table
|
||||
if registered[reg.widget] == nil then
|
||||
registered[reg.widget] = {}
|
||||
table.insert(registered[reg.widget], reg)
|
||||
else
|
||||
already = false
|
||||
local already = false
|
||||
|
||||
for w, i in pairs(registered) do
|
||||
if w == reg.widget then
|
||||
|
@ -148,7 +144,7 @@ function regregister(reg)
|
|||
end
|
||||
end
|
||||
|
||||
-- Start timer
|
||||
-- Start the timer
|
||||
if reg.timer > 0 then
|
||||
timers[reg.update] = {
|
||||
timer = capi.timer({ timeout = reg.timer })
|
||||
|
@ -159,14 +155,12 @@ function regregister(reg)
|
|||
|
||||
-- Initial update
|
||||
reg.update()
|
||||
|
||||
-- Set running
|
||||
reg.running = true
|
||||
end
|
||||
end
|
||||
-- }}}
|
||||
|
||||
-- {{{ Unregister widget
|
||||
-- {{{ Unregister a widget
|
||||
function unregister(widget, keep, reg)
|
||||
if reg == nil then
|
||||
for w, i in pairs(registered) do
|
||||
|
@ -192,7 +186,7 @@ function unregister(widget, keep, reg)
|
|||
end
|
||||
end
|
||||
|
||||
-- Stop timer
|
||||
-- Stop the timer
|
||||
if timers[reg.update].timer.started then
|
||||
timers[reg.update].timer:stop()
|
||||
end
|
||||
|
@ -202,7 +196,7 @@ function unregister(widget, keep, reg)
|
|||
end
|
||||
-- }}}
|
||||
|
||||
-- {{{ Suspend vicious, halt all widget updates
|
||||
-- {{{ Suspend vicious
|
||||
function suspend()
|
||||
for w, i in pairs(registered) do
|
||||
for _, v in pairs(i) do
|
||||
|
@ -212,7 +206,7 @@ function suspend()
|
|||
end
|
||||
-- }}}
|
||||
|
||||
-- {{{ Activate vicious, restart all widget updates
|
||||
-- {{{ Activate vicious
|
||||
function activate(widget)
|
||||
for w, i in pairs(registered) do
|
||||
if widget == nil or w == widget then
|
||||
|
@ -224,7 +218,7 @@ function activate(widget)
|
|||
end
|
||||
-- }}}
|
||||
|
||||
-- {{{ Update widget
|
||||
-- {{{ Update a widget
|
||||
function update(widget, reg, disablecache)
|
||||
-- Check if there are any equal widgets
|
||||
if reg == nil then
|
||||
|
@ -242,8 +236,7 @@ function update(widget, reg, disablecache)
|
|||
local t = os.time()
|
||||
local data = {}
|
||||
|
||||
-- Check if we have output chached for this widget newer than last
|
||||
-- widget update
|
||||
-- Do we have output chached for a widget newer than last update
|
||||
if widget_cache[reg.type] ~= nil then
|
||||
local c = widget_cache[reg.type]
|
||||
|
||||
|
|
1
load.lua
1
load.lua
|
@ -20,7 +20,6 @@ local function worker(format)
|
|||
local line = f:read("*line")
|
||||
f:close()
|
||||
|
||||
-- Get load data
|
||||
local avg1, avg5, avg15 =
|
||||
line:match("([%d]*%.[%d]*)%s([%d]*%.[%d]*)%s([%d]*%.[%d]*)")
|
||||
|
||||
|
|
3
mbox.lua
3
mbox.lua
|
@ -21,12 +21,9 @@ local function worker(format, mbox)
|
|||
-- mbox could be huge, get a 15kb chunk from EOF
|
||||
-- * attachments could be much bigger than this
|
||||
f:seek("end", -15360)
|
||||
|
||||
-- Get data
|
||||
local text = f:read("*all")
|
||||
f:close()
|
||||
|
||||
-- Find subject lines
|
||||
for match in string.gfind(text, "Subject: ([^\n]*)") do
|
||||
subject = match
|
||||
end
|
||||
|
|
|
@ -21,17 +21,11 @@ local function worker(format, mbox)
|
|||
local total = 0
|
||||
|
||||
-- Open the mbox
|
||||
--
|
||||
-- If we had LuaFileSystem we could check the mtime and size of
|
||||
-- the file and if they didn't change since the last read we could
|
||||
-- return the old, cached, count. However, we didn't rely on extra
|
||||
-- libraries to this point so we won't start now.
|
||||
local f = io.open(mbox)
|
||||
|
||||
while true do
|
||||
-- Read the mbox line by line, if we are going to read some
|
||||
-- *HUGE* folders then switch to reading chunks. It's why we are
|
||||
-- not reading the whole file at once in the first place.
|
||||
-- *HUGE* folders then switch to reading chunks
|
||||
local lines = f:read("*line")
|
||||
if not lines then break end
|
||||
|
||||
|
|
6
mdir.lua
6
mdir.lua
|
@ -16,12 +16,6 @@ module("vicious.mdir")
|
|||
|
||||
-- {{{ Maildir widget type
|
||||
local function worker(format, mdir)
|
||||
-- Like with the mbox count widget, we would benefit from the
|
||||
-- LuaFileSystem library. However, we didn't rely on extra
|
||||
-- libraries to this point so we won't start now. Widgets like
|
||||
-- this one are not agressive like CPU or NET, so we can keep it
|
||||
-- simple, find is OK with me if we execute every >60s
|
||||
--
|
||||
-- Initialise counters
|
||||
local newcount = 0
|
||||
local curcount = 0
|
||||
|
|
1
mem.lua
1
mem.lua
|
@ -20,7 +20,6 @@ local function worker(format)
|
|||
-- Get meminfo
|
||||
local f = io.open("/proc/meminfo")
|
||||
|
||||
-- Get data
|
||||
for line in f:lines() do
|
||||
if line:match("^MemTotal.*") then
|
||||
mem_total = math.floor(tonumber(line:match("([%d]+)")) / 1024)
|
||||
|
|
4
mpd.lua
4
mpd.lua
|
@ -16,10 +16,6 @@ module("vicious.mpd")
|
|||
|
||||
-- {{{ MPD widget type
|
||||
local function worker(format)
|
||||
-- This one is as simple as they come. Using sockets or expanding
|
||||
-- it is a lost cause since there are already a few MPD Lua libs
|
||||
-- written for awesome. Use them.
|
||||
--
|
||||
-- Get data from mpc
|
||||
local f = io.popen("mpc")
|
||||
local np = f:read("*line")
|
||||
|
|
3
net.lua
3
net.lua
|
@ -25,7 +25,6 @@ local function worker(format)
|
|||
local f = io.open("/proc/net/dev")
|
||||
local args = {}
|
||||
|
||||
-- Format data
|
||||
for line in f:lines() do
|
||||
-- Match wmaster0 as well as rt0 (multiple leading spaces)
|
||||
if line:match("^[%s]?[%s]?[%s]?[%s]?[%w]+:") then
|
||||
|
@ -48,7 +47,7 @@ local function worker(format)
|
|||
args["{"..name.." tx_gb}"] = math.floor(send/1024/1024/1024*10)/10
|
||||
|
||||
if nets[name] == nil then
|
||||
-- Default values on our first run
|
||||
-- Default values on the first run
|
||||
nets[name] = {}
|
||||
args["{"..name.." down}"] = "n/a"
|
||||
args["{"..name.." up}"] = "n/a"
|
||||
|
|
4
org.lua
4
org.lua
|
@ -26,7 +26,7 @@ local function worker(format, files)
|
|||
local soon = today + 24 * 3600 * 3 -- 3 days ahead is close
|
||||
local future = today + 24 * 3600 * 7 -- 7 days ahead is maximum
|
||||
|
||||
-- Initialise count table
|
||||
-- Initialise counters
|
||||
local count = {
|
||||
past = 0,
|
||||
today = 0,
|
||||
|
@ -38,7 +38,6 @@ local function worker(format, files)
|
|||
for i=1, #files do
|
||||
local f = io.open(files[i])
|
||||
|
||||
-- Parse the agenda
|
||||
for line in f:lines() do
|
||||
local scheduled = string.find(line, "SCHEDULED:")
|
||||
local closed = string.find(line, "CLOSED:")
|
||||
|
@ -47,7 +46,6 @@ local function worker(format, files)
|
|||
if (scheduled and not closed) or (deadline and not closed) then
|
||||
local b, e, y, m, d = string.find(line, "(%d%d%d%d)-(%d%d)-(%d%d)")
|
||||
|
||||
-- Enumerate agenda items
|
||||
if b then
|
||||
local t = os.time{ year = y, month = m, day = d }
|
||||
|
||||
|
|
21
pacman.lua
21
pacman.lua
|
@ -16,27 +16,22 @@ module("vicious.pacman")
|
|||
|
||||
-- {{{ Pacman widget type
|
||||
local function worker(format)
|
||||
-- Initialise counters
|
||||
local updates = 0
|
||||
|
||||
-- Check if updates are available
|
||||
local f = io.popen("pacman -Qu")
|
||||
|
||||
-- Initialise updates
|
||||
local updates = 0
|
||||
|
||||
-- Get data
|
||||
for line in f:lines() do
|
||||
-- Pacman 3.3 returns one package on a line, without any extra
|
||||
-- information
|
||||
updates = updates + 1
|
||||
|
||||
-- Pacman 3.2 returns 'Targets:' followed by a number of
|
||||
-- available updates and a list of packages all on one
|
||||
-- line. Since the number is provided we don't have to count
|
||||
-- them
|
||||
-- Pacman 3.2 provides the number of available updates
|
||||
--updates = line:match("^Targets[%s]%(([%d]+)%)") or 0
|
||||
-- If the count changed then break out of the loop
|
||||
---- If the count changed then break out of the loop
|
||||
--if tonumber(updates) > 0 then
|
||||
-- break
|
||||
--end
|
||||
|
||||
-- Pacman 3.3 returns one line per package
|
||||
updates = updates + 1
|
||||
end
|
||||
f:close()
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ local function worker(format, thermal_zone)
|
|||
local line = f:read("*line")
|
||||
f:close()
|
||||
|
||||
-- Get temperature data
|
||||
local temperature = line:match("[%d]?[%d]?[%d]")
|
||||
|
||||
return {temperature}
|
||||
|
|
|
@ -22,9 +22,7 @@ local function worker(format)
|
|||
local line = f:read("*line")
|
||||
f:close()
|
||||
|
||||
-- Format data
|
||||
local total_uptime = math.floor(tonumber(line:match("[%d%.]+")))
|
||||
|
||||
local uptime_days = math.floor(total_uptime / (3600 * 24))
|
||||
local uptime_hours = math.floor((total_uptime % (3600 * 24)) / 3600)
|
||||
local uptime_minutes = math.floor(((total_uptime % (3600 * 24)) % 3600) / 60)
|
||||
|
|
|
@ -21,13 +21,10 @@ local function worker(format, channel)
|
|||
local mixer = f:read("*all")
|
||||
f:close()
|
||||
|
||||
-- Get volume level
|
||||
local volume_level = string.match(mixer, "([%d]?[%d]?[%d])%%")
|
||||
|
||||
-- Don't break progressbars
|
||||
if volume_level == nil then
|
||||
return {0}
|
||||
end
|
||||
if volume_level == nil then return {0} end
|
||||
|
||||
return {volume_level}
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ module("vicious.weather")
|
|||
-- {{{ Weather widget type
|
||||
local function worker(format, station)
|
||||
-- US National Oceanic and Atmospheric Administration
|
||||
-- * Station (ICAO) codes: http://www.rap.ucar.edu/weather/surface/stations.txt
|
||||
-- * ICAO codes: http://www.rap.ucar.edu/weather/surface/stations.txt
|
||||
local noaa = "http://weather.noaa.gov/pub/data/observations/metar/decoded/"
|
||||
|
||||
-- Get info from a weather station
|
||||
|
@ -26,11 +26,8 @@ local function worker(format, station)
|
|||
local ws = f:read("*all")
|
||||
f:close()
|
||||
|
||||
-- Setup tables
|
||||
-- Default values
|
||||
local weather = {
|
||||
-- Some of the weather symbols would look nice if prepended to
|
||||
-- the final output, but it is up to the user to do that
|
||||
-- * http://www.alanwood.net/unicode/miscellaneous_symbols.html
|
||||
["{city}"] = "N/A",
|
||||
["{wind}"] = "N/A",
|
||||
["{windmph}"] = "N/A",
|
||||
|
|
5
wifi.lua
5
wifi.lua
|
@ -19,13 +19,12 @@ module("vicious.wifi")
|
|||
|
||||
-- {{{ Wireless widget type
|
||||
local function worker(format, iface)
|
||||
-- Get data from iwconfig, on distributions where it is executable
|
||||
-- by users, and /sbin or /usr/sbin is in their path
|
||||
-- Get data from iwconfig (where available)
|
||||
local f = io.popen("iwconfig " .. iface)
|
||||
local iw = f:read("*all")
|
||||
f:close()
|
||||
|
||||
-- Setup tables
|
||||
-- Default values
|
||||
local winfo = {
|
||||
["{ssid}"] = "N/A",
|
||||
["{mode}"] = "N/A",
|
||||
|
|
Loading…
Reference in New Issue