summaryrefslogtreecommitdiff
path: root/pactl-widget/utils.lua
diff options
context:
space:
mode:
Diffstat (limited to 'pactl-widget/utils.lua')
-rw-r--r--pactl-widget/utils.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/pactl-widget/utils.lua b/pactl-widget/utils.lua
new file mode 100644
index 0000000..52e7869
--- /dev/null
+++ b/pactl-widget/utils.lua
@@ -0,0 +1,28 @@
+local utils = {}
+
+
+function utils.trim(str)
+ return string.match(str, "^%s*(.-)%s*$")
+end
+
+function utils.split(string_to_split, separator)
+ if separator == nil then separator = "%s" end
+ local t = {}
+
+ for str in string.gmatch(string_to_split, "([^".. separator .."]+)") do
+ table.insert(t, str)
+ end
+
+ return t
+end
+
+function utils.popen_and_return(cmd)
+ local handle = io.popen(cmd)
+ local result = handle:read("*a")
+ handle:close()
+
+ return result
+end
+
+
+return utils