summaryrefslogtreecommitdiff
path: root/pactl-widget/utils.lua
blob: 52e786958c638ab06bc4a746772683e83b5093b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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