aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README5
-rw-r--r--pkg.lua19
2 files changed, 15 insertions, 9 deletions
diff --git a/README b/README
index ceaf4a8..8761735 100644
--- a/README
+++ b/README
@@ -247,8 +247,9 @@ vicious.widgets.org
of tasks for today, 3rd as count of tasks for the next 3 days and
4th as count of tasks to do in the week
-vicious.widgets.pacman
- - provides number of pending updates on Arch Linux
+vicious.widgets.pkg
+ - provides number of pending updates on GNU/Linux
+ - takes the distribution name as an argument, i.e. "Arch"
- returns 1st value as the count of available updates
vicious.widgets.mpd
diff --git a/pkg.lua b/pkg.lua
index 917b893..b0cf501 100644
--- a/pkg.lua
+++ b/pkg.lua
@@ -4,8 +4,8 @@
---------------------------------------------------
-- {{{ Grab environment
-local tonumber = tonumber
local io = { popen = io.popen }
+local math = { max = math.max }
local setmetatable = setmetatable
-- }}}
@@ -15,21 +15,26 @@ module("vicious.pkg")
-- {{{ Packages widget type
-local function worker(format)
+local function worker(format, dist)
-- Initialise counters
local updates = 0
+ local manager = {
+ ["Arch"] = { cmd = "pacman -Qu" },
+ ["Arch S"] = { cmd = "pacman -Sup", sub = 2 },
+ ["Debian"] = { cmd = "apt-show-versions -u -b" },
+ ["Fedora"] = { cmd = "yum list updates", sub = 3 }
+ }
- -- Check if updates are available on Arch
- local f = io.popen("pacman -Qu")
- --- Exclude IgnorePkg and count deps
- ---local f = io.popen("pacman -Sup")
+ -- Check if updates are available
+ local pkg = manager[dist]
+ local f = io.popen(pkg.cmd)
for line in f:lines() do
updates = updates + 1
end
f:close()
- return {updates}
+ return {pkg.sub and math.max(updates-pkg.sub, 0) or updates}
end
-- }}}