summaryrefslogtreecommitdiff
path: root/.i3/scripts/conky_helpers.lua
diff options
context:
space:
mode:
Diffstat (limited to '.i3/scripts/conky_helpers.lua')
-rw-r--r--.i3/scripts/conky_helpers.lua31
1 files changed, 31 insertions, 0 deletions
diff --git a/.i3/scripts/conky_helpers.lua b/.i3/scripts/conky_helpers.lua
new file mode 100644
index 0000000..b796753
--- /dev/null
+++ b/.i3/scripts/conky_helpers.lua
@@ -0,0 +1,31 @@
+-- escape special chars to be usable in JSON
+function conky_json(str)
+ return string.gsub(conky_parse(str), '([\\"])', '\\%1')
+end
+
+-- format strings of 'xxh xxm xxs' as 'hh:mm'
+function conky_utime(str)
+ return string.format("%d:%02d", string.match(conky_parse(str), '(%d+)h (%d+)m (%d+)s'))
+end
+
+-- format all the args as a JSON dictionary
+-- args are as key1, value1, key2, value2, ...
+function conky_i3(...)
+ d = "{"
+ key = true
+ for i,v in ipairs(arg) do
+ if key then
+ d = d .. "\"" .. v .. "\":"
+ key = false
+ else
+ d = d .. conky_parse(v)
+ if string.sub(v, -1) == '"' then
+ if i < table.getn(arg) then d = d .. "," end
+ key = true
+ else
+ d = d .. " "
+ end
+ end
+ end
+ return d .. "}"
+end