From 71ea0f3dbfcd358fb4c64c6450b2518092b8c449 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Tue, 26 Nov 2013 18:10:41 +0100 Subject: [PATCH 01/23] README: enable caching in vicious.widgets.cpu example --- README | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README b/README index 79c40bd..24be226 100644 --- a/README +++ b/README @@ -445,10 +445,12 @@ CPU usage widget cpuwidget:set_background_color("#494B4F") cpuwidget:set_color({ type = "linear", from = { 0, 0 }, to = { 50, 0 }, stops = { { 0, "#FF5656" }, { 0.5, "#88A175" }, { 1, "#AECF96" }}) + vicious.cache(vicious.widgets.cpu) vicious.register(cpuwidget, vicious.widgets.cpu, "$1", 3) - updated every 3 seconds, feeds the graph with total usage - percentage of all CPUs/cores + percentage of all CPUs/cores and enable caching of this widget + type Format functions From f36997bab4362e889c2cc8aa06ae4da57b9f1953 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Mon, 2 Dec 2013 19:06:41 +0100 Subject: [PATCH 02/23] README: explain wifi abbreviations linp and sign --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 24be226..f86e6bf 100644 --- a/README +++ b/README @@ -218,7 +218,7 @@ vicious.widgets.wifi - provides wireless information for a requested interface - takes the network interface as an argument, i.e. "wlan0" - returns a table with string keys: {ssid}, {mode}, {chan}, {rate}, - {link}, {linp} and {sign} + {link}, {linp} (link quality in percent) and {sign} (signal level) vicious.widgets.mbox - provides the subject of last e-mail in a mbox file From dc556e5415ee1d1b3b74508e016fb1693d55a311 Mon Sep 17 00:00:00 2001 From: Martin Ueding Date: Thu, 12 Dec 2013 13:35:39 +0100 Subject: [PATCH 03/23] bat: Use a real minus sign for the charging status MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, a simple hyphen (“-”) was used to show that the battery is discharging. The minus sign is a distinct char, and also distinct from the en-dash (“–”) and the em-dash (“—”). With this commit, I put in a unicode “MINUS SIGN” (0x2212) which I created with a Digraph in Vim `^k-2`. Signed-off-by: Adrian C. (anrxc) --- widgets/bat.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widgets/bat.lua b/widgets/bat.lua index 34d1124..76a9d4c 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -30,7 +30,7 @@ local function worker(format, warg) ["Unknown\n"] = "⌁", ["Charged\n"] = "↯", ["Charging\n"] = "+", - ["Discharging\n"] = "-" + ["Discharging\n"] = "−" } -- Check if the battery is present From 7961ca145479e364fe64ec082e24545bd0f3c4bb Mon Sep 17 00:00:00 2001 From: Jonathan McCrohan Date: Sun, 15 Dec 2013 02:48:00 +0100 Subject: [PATCH 04/23] weather: add support for dew point Signed-off-by: Jonathan McCrohan Signed-off-by: Adrian C. (anrxc) --- README | 3 ++- widgets/weather.lua | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README b/README index f86e6bf..09b7abd 100644 --- a/README +++ b/README @@ -282,7 +282,8 @@ vicious.widgets.weather - provides weather information for a requested station - takes the ICAO station code as an argument, i.e. "LDRI" - returns a table with string keys: {city}, {wind}, {windmph}, - {windkmh}, {sky}, {weather}, {tempf}, {tempc}, {humid}, {press} + {windkmh}, {sky}, {weather}, {tempf}, {tempc}, {humid}, {dewf}, + {dewc}, {press} vicious.widgets.date - provides access to os.date, with optional time formatting provided diff --git a/widgets/weather.lua b/widgets/weather.lua index 356f32f..029df7e 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -28,6 +28,8 @@ local _weather = { ["{weather}"] = "N/A", ["{tempf}"] = "N/A", ["{tempc}"] = "N/A", + ["{dewf}"] = "N/A", + ["{dewc}"] = "N/A", ["{humid}"] = "N/A", ["{press}"] = "N/A" } @@ -58,6 +60,8 @@ local function worker(format, warg) string.match(ws, "Weather:[%s](.-)[%c]") or _weather["{weather}"] _weather["{tempf}"] = -- Temperature in fahrenheit string.match(ws, "Temperature:[%s]([%-]?[%d%.]+).*[%c]") or _weather["{tempf}"] + _weather["{dewf}"] = -- Dew Point in fahrenheit + string.match(ws, "Dew[%s]Point:[%s]([%-]?[%d%.]+).*[%c]") or _weather["{dewf}"] _weather["{humid}"] = -- Relative humidity in percent string.match(ws, "Relative[%s]Humidity:[%s]([%d]+)%%") or _weather["{humid}"] _weather["{press}"] = -- Pressure in hPa @@ -71,6 +75,10 @@ local function worker(format, warg) if _weather["{tempf}"] ~= "N/A" then _weather["{tempf}"] = tonumber(_weather["{tempf}"]) _weather["{tempc}"] = math.ceil((_weather["{tempf}"] - 32) * 5/9) + end -- Dew Point in °C if °F was available + if _weather["{dewf}"] ~= "N/A" then + _weather["{dewf}"] = tonumber(_weather["{dewf}"]) + _weather["{dewc}"] = math.ceil((_weather["{dewf}"] - 32) * 5/9) end -- Capitalize some stats so they don't look so out of place if _weather["{sky}"] ~= "N/A" then _weather["{sky}"] = helpers.capitalize(_weather["{sky}"]) From 52cbb64144b3134a0bf131c91fbcf25650a0b219 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Sun, 15 Dec 2013 18:20:50 +0100 Subject: [PATCH 05/23] Revert "init: emit timeout instead of forced update" This reverts commit 932bd8dfc because with shared timers feature from commit 211d4509 shared timer emitting timeout can update all shared objects. --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 46fdec5..2d28980 100644 --- a/init.lua +++ b/init.lua @@ -132,7 +132,7 @@ local function regregister(reg) tm:start() end -- Initial update - tm:emit_signal("timeout") + reg.update() end reg.running = true end From c51e13c35d042eb34a461015c4f10c693050a6f4 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Sun, 15 Dec 2013 18:34:55 +0100 Subject: [PATCH 06/23] init: stop allocating reg table functions with properties This partly reverts commit f1844decefb because a user reported seeing nil passed as the object to the reg.update() function. --- init.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/init.lua b/init.lua index 2d28980..c154e20 100644 --- a/init.lua +++ b/init.lua @@ -152,12 +152,11 @@ function vicious.register(widget, wtype, format, timer, warg) timer = timer, warg = warg, widget = widget, - - -- Update function - update = function () - update(widget, reg) - end, } + -- Set functions + reg.update = function () + update(widget, reg) + end -- Default to 2s timer if reg.timer == nil then From 76269896fc4db8f6243a59465f9af9994f72c47c Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Sun, 15 Dec 2013 19:13:35 +0100 Subject: [PATCH 07/23] README: write a list of major contributors to the project Thank you all, and thanks very much to those who contributed only once and are omitted from the documentation. --- README | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README b/README index 09b7abd..5f4cdd9 100644 --- a/README +++ b/README @@ -568,9 +568,7 @@ Wicked written by: Vicious written by: - Adrian C. (anrxc) -Vicious contributors: - - Michael Unterkalmsteiner - - Martin Striz +Vicious major contributors: - Benedikt Sauer - Greg D. - Henning Glawe @@ -579,3 +577,6 @@ Vicious contributors: - Hagen Schink - Jörg Thalheim - Arvydas Sidorenko + - Dodo The Last + - ... + - Consult git log for a complete list of contributors From 946271c41d70e7ce5633380b4114dcd775fb73bb Mon Sep 17 00:00:00 2001 From: Normal Ra Date: Sun, 22 Dec 2013 13:09:16 +0100 Subject: [PATCH 08/23] bat: expose information on battery wear and tear Modern batteries should expose information about their design capacity which we can compare to current capacity and deduce how much 'wear' the battery got and expose that as a negative value percentage. Feature sent in August took a while to convince the maintainer many modern batteries provide this information. Signed-off-by: Adrian C. (anrxc) --- README | 7 ++++--- widgets/bat.lua | 18 +++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/README b/README index 5f4cdd9..4f1ff50 100644 --- a/README +++ b/README @@ -159,11 +159,12 @@ vicious.widgets.uptime for 5 minutes and 6th for 15 minutes vicious.widgets.bat - - provides state, charge, and remaining time for a requested battery + - provides state, charge, remaining time and wear for a requested + battery - takes battery ID as an argument, i.e. "BAT0" - returns 1st value as state of requested battery, 2nd as charge - level in percent and 3rd as remaining (charging or discharging) - time + level in percent, 3rd as remaining (charging or discharging) + time and 4th as the wear level in percent vicious.widgets.mem - provides RAM and Swap usage statistics diff --git a/widgets/bat.lua b/widgets/bat.lua index 76a9d4c..454e43f 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -1,6 +1,7 @@ --------------------------------------------------- -- Licensed under the GNU General Public License v2 -- * (c) 2010, Adrian C. +-- * (c) 2013, NormalRa --------------------------------------------------- -- {{{ Grab environment @@ -15,7 +16,7 @@ local math = { -- }}} --- Bat: provides state, charge, and remaining time for a requested battery +-- Bat: provides state, charge, remaining time, and wear for a requested battery -- vicious.widgets.bat local bat = {} @@ -35,7 +36,7 @@ local function worker(format, warg) -- Check if the battery is present if battery.present ~= "1\n" then - return {battery_state["Unknown\n"], 0, "N/A"} + return {battery_state["Unknown\n"], 0, "N/A", 0} end @@ -45,14 +46,17 @@ local function worker(format, warg) -- Get capacity information if battery.charge_now then remaining, capacity = battery.charge_now, battery.charge_full + capacity_design = battery.charge_full_design or capacity elseif battery.energy_now then remaining, capacity = battery.energy_now, battery.energy_full + capacity_design = battery.energy_full_design or capacity else - return {battery_state["Unknown\n"], 0, "N/A"} + return {battery_state["Unknown\n"], 0, "N/A", 0} end - -- Calculate percentage (but work around broken BAT/ACPI implementations) + -- Calculate capacity and wear percentage (but work around broken BAT/ACPI implementations) local percent = math.min(math.floor(remaining / capacity * 100), 100) + local wear = math.floor(100 - capacity / capacity_design * 100) -- Get charge information @@ -61,7 +65,7 @@ local function worker(format, warg) elseif battery.power_now then rate = tonumber(battery.power_now) else - return {state, percent, "N/A"} + return {state, percent, "N/A", wear} end -- Calculate remaining (charging or discharging) time @@ -73,7 +77,7 @@ local function worker(format, warg) elseif state == "-" then timeleft = tonumber(remaining) / tonumber(rate) else - return {state, percent, time} + return {state, percent, time, wear} end -- Calculate time @@ -83,7 +87,7 @@ local function worker(format, warg) time = string.format("%02d:%02d", hoursleft, minutesleft) end - return {state, percent, time} + return {state, percent, time, wear} end -- }}} From 3ef0f11d8ecea0c6461db4d5bbf2d42fcd030153 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Sun, 22 Dec 2013 13:23:37 +0100 Subject: [PATCH 09/23] Next release, tag 2.1.2 --- CHANGES | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CHANGES b/CHANGES index 4e33af5..d2bdb80 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,24 @@ Full changelog is available online: http://git.sysphere.org/vicious/log/?showmsg=1 --------------------------------------------------- +946271c bat: expose information on battery wear and tear +7626989 README: write a list of major contributors to the project +c51e13c init: stop allocating reg table functions with properties +52cbb64 Revert "init: emit timeout instead of forced update" +7961ca1 weather: add support for dew point +dc556e5 bat: Use a real minus sign for the charging status +f36997b README: explain wifi abbreviations linp and sign +71ea0f3 README: enable caching in vicious.widgets.cpu example +211d450 init: share timers when possible +75cd103 Revert "mpd: workaround command termination bug in mpd server v0.18" +a6a73f4 mpd: workaround command termination bug in mpd server v0.18 +c795642 README: update awesome usage examples for v3.5 +563cb6f pkg: revert to pacman as default Arch method, checkupdates optional +01b2302 pkg: use checkupdates on Arch Linux. +2641bf8 contrib: add Open Weather and ATi graphics widget types +0fd4fc5 mboxc: Fixed typo in setmetatable after ported to lua 5.2 +052d19e README: explain vicious is a generic WM widget library +bb891d6 Next release, tag 2.1.1 fac688e wifi: add support for /usr/bin binary path f7fdd90 README: usage examples are for awesome version 3.4 d63343e contrib: add buildbot monitoring widget From bfbc1bdd5158ab88511de5670498647e9e29db45 Mon Sep 17 00:00:00 2001 From: Adam Lee Date: Wed, 4 Dec 2013 09:32:14 +0100 Subject: [PATCH 10/23] volume: get the normalized volume like alsamixer and DE's indicator Or the percentage value will be different from alsamixer or desktop environment's indicator, which confuses users. Quote from amixer's manpage, "Use the mapped volume for evaluating the percentage representation like alsamixer, to be more natural for human ear." ref: http://git.alsa-project.org/?p=alsa-utils.git;a=blob;f=alsamixer/volume_mapping.c Signed-off-by: Adam Lee Signed-off-by: Adrian C. (anrxc) --- widgets/volume.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widgets/volume.lua b/widgets/volume.lua index 3baa7e6..2a7d377 100644 --- a/widgets/volume.lua +++ b/widgets/volume.lua @@ -26,7 +26,7 @@ local function worker(format, warg) } -- Get mixer control contents - local f = io.popen("amixer get " .. warg) + local f = io.popen("amixer -M get " .. warg) local mixer = f:read("*all") f:close() From 6e16a412efc190e450b14dd5f53261e33ec99379 Mon Sep 17 00:00:00 2001 From: Lyderic Lefever Date: Wed, 25 Dec 2013 12:31:43 +0100 Subject: [PATCH 11/23] bat: fix broken battery remaining time (was always N/A) Bug was introduced in commit dc556e5415 and the new discharging symbol. Signed-off-by: Adrian C. (anrxc) --- widgets/bat.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widgets/bat.lua b/widgets/bat.lua index 454e43f..1f491d9 100644 --- a/widgets/bat.lua +++ b/widgets/bat.lua @@ -74,7 +74,7 @@ local function worker(format, warg) if rate ~= nil and rate ~= 0 then if state == "+" then timeleft = (tonumber(capacity) - tonumber(remaining)) / tonumber(rate) - elseif state == "-" then + elseif state == "−" then timeleft = tonumber(remaining) / tonumber(rate) else return {state, percent, time, wear} From df19dac43eee3f15695e97a6eaec70b2a3ed85dd Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Sat, 4 Jan 2014 17:15:05 +0100 Subject: [PATCH 12/23] Next release, tag 2.1.3 --- CHANGES | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES b/CHANGES index d2bdb80..ce6b144 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,9 @@ Full changelog is available online: http://git.sysphere.org/vicious/log/?showmsg=1 --------------------------------------------------- +6e16a41 bat: fix broken battery remaining time (was always N/A) +bfbc1bd volume: get the normalized volume like alsamixer and DE's indicator +3ef0f11 Next release, tag 2.1.2 946271c bat: expose information on battery wear and tear 7626989 README: write a list of major contributors to the project c51e13c init: stop allocating reg table functions with properties From 178bc65f1b5d3133e34a76b96dac484fe8a07e1e Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Sun, 9 Feb 2014 19:28:28 +0100 Subject: [PATCH 13/23] contrib: import nvidia SMI widget type Right now nvsmi is just interested in temperature information. My streaming server GPU 'fell of the bus' last night while decoding video, I suspect overheating. --- contrib/README | 5 +++++ contrib/nvsmi.lua | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 contrib/nvsmi.lua diff --git a/contrib/README b/contrib/README index 0523b66..235599c 100644 --- a/contrib/README +++ b/contrib/README @@ -68,6 +68,11 @@ vicious.contrib.openweather - returns a table with string keys: {city}, {wind deg}, {wind aim}, {wind kmh}, {wind mps}, {sky}, {weather}, {temp c}, {humid}, {press} +vicious.contrib.nvsmi + - provides (very basic) information about Nvidia GPU status from SMI + - takes optional card ID as an argument, i.e. "1", or defaults to ID 0 + - returns 1st value as temperature of requested graphics device + vicious.contrib.ossvol - diff --git a/contrib/nvsmi.lua b/contrib/nvsmi.lua new file mode 100644 index 0000000..e68d4a1 --- /dev/null +++ b/contrib/nvsmi.lua @@ -0,0 +1,42 @@ +--------------------------------------------------- +-- Licensed under the GNU General Public License v2 +-- * (c) 2014, Adrian C. +--------------------------------------------------- + +-- {{{ Grab environment +local tonumber = tonumber +local io = { popen = io.popen } +local setmetatable = setmetatable +local string = { match = string.match } +-- }}} + + +-- nvsmi: provides GPU information from nvidia SMI +-- vicious.contrib.nvsmi +local nvsmi = {} + + +-- {{{ GPU Information widget type +local function worker(format, warg) + -- Fallback to querying first device + if not warg then warg = "0" end + + -- Get data from smi + -- * Todo: support more; MEMORY,UTILIZATION,ECC,POWER,CLOCK,COMPUTE,PIDS,PERFORMANCE + local f = io.popen("nvidia-smi -q -d TEMPERATURE -i " .. warg) + local smi = f:read("*all") + f:close() + + -- Not installed + if smi == nil then return {0} end + + -- Get temperature information + local _thermal = string.match(smi, "Gpu[%s]+:[%s]([%d]+)[%s]C") + -- Handle devices without data + if _thermal == nil then return {0} end + + return {tonumber(_thermal)} +end +-- }}} + +return setmetatable(nvsmi, { __call = function(_, ...) return worker(...) end }) From 9fc02f16da6c967374f29caf9caaf8725310da41 Mon Sep 17 00:00:00 2001 From: Andrew Merenbach Date: Fri, 7 Mar 2014 22:23:18 +0200 Subject: [PATCH 14/23] fs: add FreeBSD mount point detection to regexp Signed-off-by: Adrian C. (anrxc) --- widgets/fs.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widgets/fs.lua b/widgets/fs.lua index c0b7f16..7832b1f 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -32,7 +32,7 @@ local function worker(format, warg) for line in f:lines() do -- Match: (size) (used)(avail)(use%) (mount) local s = string.match(line, "^.-[%s]([%d]+)") local u,a,p = string.match(line, "([%d]+)[%D]+([%d]+)[%D]+([%d]+)%%") - local m = string.match(line, "%%[%s]([%p%w]+)") + local m = string.match(line, "%%[%s]+([%p%w]+)") if u and m then -- Handle 1st line and broken regexp helpers.uformat(fs_info, m .. " size", s, unit) From 50fd2334b6a720f798782f7690287b71642cb9a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Zugmeyer?= Date: Sat, 8 Nov 2014 18:14:03 +0100 Subject: [PATCH 15/23] gmail: fix subject when gmail feed is in one line For some time now, gmail feeds are in a single line. The goal of this patch is to handle both cases (single and multiline). It will find the text between title tags after the first entry tag. Since the first feed title is skiped with this regex, title regexes aren't needed anymore. Signed-off-by: Adrian C. (anrxc) --- widgets/gmail.lua | 54 +++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/widgets/gmail.lua b/widgets/gmail.lua index ba8e731..dbd7d19 100644 --- a/widgets/gmail.lua +++ b/widgets/gmail.lua @@ -10,7 +10,6 @@ local io = { popen = io.popen } local setmetatable = setmetatable local helpers = require("vicious.helpers") local string = { - find = string.find, match = string.match } -- }}} @@ -23,18 +22,9 @@ local gmail = {} -- {{{ Variable definitions local rss = { - inbox = { - "https://mail.google.com/mail/feed/atom", - "Gmail %- Inbox" - }, - unread = { - "https://mail.google.com/mail/feed/atom/unread", - "Gmail %- Label" - }, - --labelname = { - -- "https://mail.google.com/mail/feed/atom/labelname", - -- "Gmail %- Label" - --}, + inbox = "https://mail.google.com/mail/feed/atom", + unread = "https://mail.google.com/mail/feed/atom/unread", + --labelname = "https://mail.google.com/mail/feed/atom/labelname", } -- Default is just Inbox @@ -49,31 +39,31 @@ local mail = { -- {{{ Gmail widget type local function worker(format, warg) -- Get info from the Gmail atom feed - local f = io.popen("curl --connect-timeout 1 -m 3 -fsn " .. feed[1]) + local f = io.popen("curl --connect-timeout 1 -m 3 -fsn " .. feed) -- Could be huge don't read it all at once, info we are after is at the top - for line in f:lines() do - mail["{count}"] = -- Count comes before messages and matches at least 0 - tonumber(string.match(line, "([%d]+)")) or mail["{count}"] + local xml = f:read(2000) - -- Find subject tags - local title = string.match(line, "(.*)") - -- If the subject changed then break out of the loop - if title ~= nil and not string.find(title, feed[2]) then - -- Check if we should scroll, or maybe truncate - if warg then - if type(warg) == "table" then - title = helpers.scroll(title, warg[1], warg[2]) - else - title = helpers.truncate(title, warg) - end + mail["{count}"] = -- Count comes before messages and matches at least 0 + tonumber(string.match(xml, "([%d]+)")) or mail["{count}"] + + -- Find subject tag + local title = string.match(xml, ".-(.-)") + + if title ~= nil then + -- Check if we should scroll, or maybe truncate + if warg then + if type(warg) == "table" then + title = helpers.scroll(title, warg[1], warg[2]) + else + title = helpers.truncate(title, warg) end - - -- Spam sanitize the subject and store - mail["{subject}"] = helpers.escape(title) - break end + + -- Spam sanitize the subject and store + mail["{subject}"] = helpers.escape(title) end + f:close() return mail From 336ce9bbd7c620226d0ef01ba58c02be12f7b90e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 12 Nov 2014 23:43:24 +0100 Subject: [PATCH 16/23] shell escape variables before passing them to the shell Signed-off-by: Adrian C. (anrxc) --- README | 8 +++++--- helpers.lua | 9 +++++++++ widgets/fs.lua | 2 +- widgets/hddtemp.lua | 4 +++- widgets/mdir.lua | 6 ++++-- widgets/volume.lua | 3 ++- widgets/weather.lua | 4 ++-- widgets/wifi.lua | 2 +- 8 files changed, 27 insertions(+), 11 deletions(-) diff --git a/README b/README index 4f1ff50..3a4f2b8 100644 --- a/README +++ b/README @@ -224,8 +224,10 @@ vicious.widgets.wifi vicious.widgets.mbox - provides the subject of last e-mail in a mbox file - takes the full path to the mbox as an argument, or a table with - 1st field as path, 2nd as maximum lenght and 3rd (optional) as - widget name - if 3rd field is present scrolling will be used + 1st field as path, 2nd as maximum length and 3rd (optional) as + widget name - if 3rd field is present scrolling will be used (note: the + path will be escaped so special variables like ~ will not work, use + os.getenv("HOME").."mail" instead to access environment variables) - returns 1st value as the subject of the last e-mail vicious.widgets.mboxc @@ -244,7 +246,7 @@ vicious.widgets.mdir vicious.widgets.gmail - provides count of new and subject of last e-mail on Gmail - takes an (optional) argument, if it's a number subject will be - truncated, if a table, with 1st field as maximum lenght and 2nd + truncated, if a table, with 1st field as maximum length and 2nd the widget name (i.e. "gmailwidget"), scrolling will be used - keeps login information in the ~/.netrc file, example: machine mail.google.com login user password pass diff --git a/helpers.lua b/helpers.lua index 4c15690..7c8dd0c 100644 --- a/helpers.lua +++ b/helpers.lua @@ -97,6 +97,15 @@ function helpers.escape(text) end -- }}} +-- {{{ Escape a string for save usage on the command line +function helpers.shellquote(s) + if s == nil then return "" end + -- use single quotes, and put single quotes into double quotes + -- the string $'b is then quoted as '$'"'"'b'"'"' + return "'" .. s:gsub("'", "'\"'\"'") .. "'" +end +-- }}} + -- {{{ Capitalize a string function helpers.capitalize(text) return text and text:gsub("([%w])([%w]*)", function(c, s) diff --git a/widgets/fs.lua b/widgets/fs.lua index 7832b1f..4b889dc 100644 --- a/widgets/fs.lua +++ b/widgets/fs.lua @@ -27,7 +27,7 @@ local function worker(format, warg) if warg then warg = "" else warg = "-l" end local fs_info = {} -- Get data from df - local f = io.popen("LC_ALL=C df -kP " .. warg) + local f = io.popen("LC_ALL=C df -kP " .. helpers.shellquote(warg)) for line in f:lines() do -- Match: (size) (used)(avail)(use%) (mount) local s = string.match(line, "^.-[%s]([%d]+)") diff --git a/widgets/hddtemp.lua b/widgets/hddtemp.lua index 85ee767..5c2b1a6 100644 --- a/widgets/hddtemp.lua +++ b/widgets/hddtemp.lua @@ -8,6 +8,7 @@ local tonumber = tonumber local io = { popen = io.popen } local setmetatable = setmetatable local string = { gmatch = string.gmatch } +local helpers = require("vicious.helpers") -- }}} @@ -22,7 +23,8 @@ local function worker(format, warg) if warg == nil then warg = 7634 end local hdd_temp = {} -- Get info from the hddtemp daemon - local f = io.popen("echo | curl --connect-timeout 1 -fsm 3 telnet://127.0.0.1:"..warg) + local quoted = helpers.shellquote(warg) + local f = io.popen("echo | curl --connect-timeout 1 -fsm 3 telnet://127.0.0.1:"..quoted) for line in f:lines() do for d, t in string.gmatch(line, "|([%/%a%d]+)|.-|([%d]+)|[CF]+|") do diff --git a/widgets/mdir.lua b/widgets/mdir.lua index d7c6f3d..bea9088 100644 --- a/widgets/mdir.lua +++ b/widgets/mdir.lua @@ -7,6 +7,7 @@ -- {{{ Grab environment local io = { popen = io.popen } local setmetatable = setmetatable +local helpers = require("vicious.helpers") -- }}} @@ -23,13 +24,14 @@ local function worker(format, warg) local count = { new = 0, cur = 0 } for i=1, #warg do + quoted_path = helpers.shellquote(warg[i]) -- Recursively find new messages - local f = io.popen("find '"..warg[i].."' -type f -wholename '*/new/*'") + local f = io.popen("find "..quoted_path.." -type f -wholename '*/new/*'") for line in f:lines() do count.new = count.new + 1 end f:close() -- Recursively find "old" messages lacking the Seen flag - local f = io.popen("find '"..warg[i].."' -type f -regex '.*/cur/.*2,[^S]*$'") + local f = io.popen("find "..quoted_path.." -type f -regex '.*/cur/.*2,[^S]*$'") for line in f:lines() do count.cur = count.cur + 1 end f:close() end diff --git a/widgets/volume.lua b/widgets/volume.lua index 2a7d377..57970a3 100644 --- a/widgets/volume.lua +++ b/widgets/volume.lua @@ -8,6 +8,7 @@ local tonumber = tonumber local io = { popen = io.popen } local setmetatable = setmetatable local string = { match = string.match } +local helpers = require("vicious.helpers") -- }}} @@ -26,7 +27,7 @@ local function worker(format, warg) } -- Get mixer control contents - local f = io.popen("amixer -M get " .. warg) + local f = io.popen("amixer -M get " .. helpers.shellquote(warg)) local mixer = f:read("*all") f:close() diff --git a/widgets/weather.lua b/widgets/weather.lua index 029df7e..632d5b9 100644 --- a/widgets/weather.lua +++ b/widgets/weather.lua @@ -40,8 +40,8 @@ local function worker(format, warg) -- Get weather forceast by the station ICAO code, from: -- * US National Oceanic and Atmospheric Administration - local noaa = "http://weather.noaa.gov/pub/data/observations/metar/decoded/" - local f = io.popen("curl --connect-timeout 1 -fsm 3 "..noaa..warg..".TXT") + local url = "http://weather.noaa.gov/pub/data/observations/metar/decoded/"..warg + local f = io.popen("curl --connect-timeout 1 -fsm 3 "..helpers.shellquote(url)..".TXT") local ws = f:read("*all") f:close() diff --git a/widgets/wifi.lua b/widgets/wifi.lua index 15666e5..973f109 100644 --- a/widgets/wifi.lua +++ b/widgets/wifi.lua @@ -58,7 +58,7 @@ local function worker(format, warg) end -- Get data from iwconfig where available - local f = io.popen(iwconfig .." ".. warg .. " 2>&1") + local f = io.popen(iwconfig .." ".. helpers.shellquote(warg) .. " 2>&1") local iw = f:read("*all") f:close() From 5869a54b201cd30988618025e63ceaa4df69d927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Zugmeyer?= Date: Sun, 16 Nov 2014 03:24:53 +0100 Subject: [PATCH 17/23] gmail: fix error when gmail.com is unreachable ex: no internet connection Signed-off-by: Adrian C. (anrxc) --- widgets/gmail.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/widgets/gmail.lua b/widgets/gmail.lua index dbd7d19..84f2125 100644 --- a/widgets/gmail.lua +++ b/widgets/gmail.lua @@ -44,6 +44,10 @@ local function worker(format, warg) -- Could be huge don't read it all at once, info we are after is at the top local xml = f:read(2000) + if xml ~= nil then + return mail + end + mail["{count}"] = -- Count comes before messages and matches at least 0 tonumber(string.match(xml, "([%d]+)")) or mail["{count}"] From 44dd0a60cfd5da71f1c0dacb2e008d566db0f14c Mon Sep 17 00:00:00 2001 From: blastmaster Date: Fri, 12 Dec 2014 12:29:51 +0100 Subject: [PATCH 18/23] new gears.timer timer implementation move from c to lua. Signed-off-by: Adrian C. (anrxc) --- init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index c154e20..c20c418 100644 --- a/init.lua +++ b/init.lua @@ -10,7 +10,7 @@ local type = type local pairs = pairs local tonumber = tonumber -local capi = { timer = timer } +local timer = (type(timer) == 'table' and timer or require("gears.timer")) local os = { time = os.time } local table = { insert = table.insert, @@ -117,7 +117,7 @@ local function regregister(reg) -- Start the timer if reg.timer > 0 then local tm = timers[reg.timer] and timers[reg.timer].timer - tm = tm or capi.timer({ timeout = reg.timer }) + tm = tm or timer({ timeout = reg.timer }) if tm.connect_signal then tm:connect_signal("timeout", reg.update) else From 340883180dcfdc91ee201001f2fc4ccb9c949728 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Sun, 28 Dec 2014 19:58:43 +0100 Subject: [PATCH 19/23] README: new FreeBSD code by Rudi Siegel I don't know for a fact there are (many) more compatible widgets than in Richard's work. I have faith there are, no offense intended. --- README | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README b/README index 3a4f2b8..dc60daa 100644 --- a/README +++ b/README @@ -312,10 +312,10 @@ holds widget types that were obsoleted or rewritten. Contrib widgets will not be imported by init unless you explicitly enable it, or load them in your rc.lua. -Richard Kolkovich, a FreeBSD user, published his vicious-fbsd -branch. If you are also a BSD user you can find his work here: +Rudi Siegel, a FreeBSD user, published his FreeBSD branch. If you are +also a BSD user you can find his work here: - - http://git.sigil.org/vicious-fbsd/ + - https://bitbucket.org/mutluyum/vicious_bsd/ Some users would like to avoid writing new modules. For them Vicious kept the old Wicked functionality, possibility to register their own From 9c535a19bdd9c05259c57725af77a21a6d41851c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sun, 22 Feb 2015 11:19:24 +0100 Subject: [PATCH 20/23] fix indentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörg Thalheim Signed-off-by: Adrian C. (anrxc) --- contrib/pulse.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/contrib/pulse.lua b/contrib/pulse.lua index 8b3298b..413b767 100644 --- a/contrib/pulse.lua +++ b/contrib/pulse.lua @@ -18,7 +18,7 @@ local string = { gmatch = string.gmatch } local math = { - floor = math.floor + floor = math.floor } -- }}} @@ -29,15 +29,15 @@ local pulse = {} -- {{{ Helper function local function pacmd(args) - local f = io.popen("pacmd "..args) - local line = f:read("*all") - f:close() - return line + local f = io.popen("pacmd "..args) + local line = f:read("*all") + f:close() + return line end local function escape(text) - local special_chars = { ["."] = "%.", ["-"] = "%-" } - return text:gsub("[%.%-]", special_chars) + local special_chars = { ["."] = "%.", ["-"] = "%-" } + return text:gsub("[%.%-]", special_chars) end local cached_sinks = {} @@ -47,10 +47,10 @@ local function get_sink_name(sink) local key = sink or 1 -- Cache requests if not cached_sinks[key] then - local line = pacmd("list-sinks") - for s in string.gmatch(line, "name: <(.-)>") do - table.insert(cached_sinks, s) - end + local line = pacmd("list-sinks") + for s in string.gmatch(line, "name: <(.-)>") do + table.insert(cached_sinks, s) + end end return cached_sinks[key] @@ -69,7 +69,7 @@ local function worker(format, sink) -- If mute return 0 (not "Mute") so we don't break progressbars if string.find(data,"set%-sink%-mute "..escape(sink).." yes") then - return {0, "off"} + return {0, "off"} end local vol = tonumber(string.match(data, "set%-sink%-volume "..escape(sink).." (0x[%x]+)")) From 02e1142749d219dbd6bb9af95c87a3a39ba19dc3 Mon Sep 17 00:00:00 2001 From: Noah Tilton Date: Sun, 22 Feb 2015 11:19:34 +0100 Subject: [PATCH 21/23] handle case if pacmd fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörg Thalheim Signed-off-by: Adrian C. (anrxc) --- contrib/pulse.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/contrib/pulse.lua b/contrib/pulse.lua index 413b767..b06bf56 100644 --- a/contrib/pulse.lua +++ b/contrib/pulse.lua @@ -30,9 +30,13 @@ local pulse = {} -- {{{ Helper function local function pacmd(args) local f = io.popen("pacmd "..args) - local line = f:read("*all") - f:close() - return line + if f == nil then + return nil + else + local line = f:read("*all") + f:close() + return line + end end local function escape(text) @@ -48,6 +52,7 @@ local function get_sink_name(sink) -- Cache requests if not cached_sinks[key] then local line = pacmd("list-sinks") + if line == nil then return nil end for s in string.gmatch(line, "name: <(.-)>") do table.insert(cached_sinks, s) end @@ -66,6 +71,7 @@ local function worker(format, sink) -- Get sink data local data = pacmd("dump") + if sink == nil then return {0, "unknown"} end -- If mute return 0 (not "Mute") so we don't break progressbars if string.find(data,"set%-sink%-mute "..escape(sink).." yes") then From 56b353e773e513f98e927bad4e8062e533e10096 Mon Sep 17 00:00:00 2001 From: Suseika Date: Thu, 4 Jun 2015 23:20:16 +0200 Subject: [PATCH 22/23] add instructions for Gmail account for vicious.widgets.gmail widget Signed-off-by: J?rg Thalheim Signed-off-by: Adrian C. (anrxc) --- README | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README b/README index dc60daa..4f1d0f6 100644 --- a/README +++ b/README @@ -251,6 +251,9 @@ vicious.widgets.gmail - keeps login information in the ~/.netrc file, example: machine mail.google.com login user password pass - returns a table with string keys: {count} and {subject} + - to be able to use this widget, make sure in your Gmail account + you disabled "two step verification" (https://support.google.com/accounts/answer/1064203) + and then "allowed access to your account for less secure apps" (https://www.google.com/settings/security/lesssecureapps) vicious.widgets.org - provides agenda statistics for Emacs org-mode From 211a2bfcf541b7821bd06fc97ba6e3c9ee8b6d94 Mon Sep 17 00:00:00 2001 From: crondog Date: Fri, 24 Jul 2015 15:08:18 +0200 Subject: [PATCH 23/23] contrib: make pulse compatible with lua5.3 String.format does like converting float to hex (or int for that matter). This fixes the issue Signed-off-by: Adrian C. (anrxc) --- contrib/pulse.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contrib/pulse.lua b/contrib/pulse.lua index b06bf56..663a6ab 100644 --- a/contrib/pulse.lua +++ b/contrib/pulse.lua @@ -18,7 +18,8 @@ local string = { gmatch = string.gmatch } local math = { - floor = math.floor + floor = math.floor, + ceil = math.ceil } -- }}} @@ -99,6 +100,8 @@ function pulse.add(percent, sink) if vol > 0x10000 then vol = 0x10000 end if vol < 0 then vol = 0 end + vol = math.ceil(vol) + local cmd = string.format("pacmd set-sink-volume %s 0x%x >/dev/null", sink, vol) return os.execute(cmd) end