2 local io = { popen = io.popen }
3 local string = { match = string.match,
9 local host = io.popen("hostname")
10 utils.host = host:read("*l")
12 function utils.is_dir(path)
13 return os.execute(('[ -d "%s" ]'):format(path))
16 local function terminal_cmd(prg, name)
17 local join = require("gears.table").join
18 local term_cmd = {terminal}
19 if terminal:match("rxvt") then
21 term_cmd = join(term_cmd, {"-name", name})
23 elseif terminal:match("wezterm") then
24 term_cmd = join(term_cmd, {"start"})
26 term_cmd = join(term_cmd, {"--class", name})
29 term_cmd = join(term_cmd, {"-e"})
31 return join(term_cmd, {prg})
34 function utils.spawn_terminal(prg, cprop, cb)
38 local name = cprop.instance
39 awful.spawn(terminal_cmd(prg, name), cprop, cb)
42 function utils.spawn_terminal_once(prg, rules, matcher, unique_id, cb)
43 local name = rules.instance
44 awful.spawn.once(terminal_cmd(prg, name), rules, matcher, unique_id, cb)
47 function utils.run_or_kill(prg, cprop, screen)
56 if not cprop.class then
60 if not cprop.instance then
64 cprop.class = string.lower(cprop.class)
65 cprop.instance = string.lower(cprop.instance)
67 for k, c in pairs(client.get()) do
68 -- apparently some steam games don't have a client class
69 if c.class == nil then
72 local class=string.lower(c.class)
73 local instance=string.lower(c.instance)
74 if string.match(class, cprop.class) and string.match(instance, cprop.instance) then
75 for i, v in ipairs(c:tags()) do
81 awful.spawn.with_shell(prg, screen)
84 -- http://awesome.naquadah.org/wiki/Autostart#Simple_way
85 function utils.run_once(prg,arg_string,pname,screen)
94 if not arg_string then
95 awful.spawn.with_shell("pgrep -f -u $USER -x '" .. pname .. "' || (" .. prg .. ")",screen)
97 awful.spawn.with_shell("pgrep -f -u $USER -x '" .. pname .. " ".. arg_string .."' || (" .. prg .. " " .. arg_string .. ")",screen)
101 function utils.get_default_sink()
102 local f = io.popen('pactl get-default-sink')
105 return string.match(line, "^sink%s*%d*%s*(.-)%s")
108 function utils.joinTables(t1, t2)
109 for k,v in ipairs(t2) do table.insert(t1, v) end return t1
112 function utils.rules.append(rules)
113 awful.rules.rules = gears.table.join(awful.rules.rules, rules)
116 function utils.globalkeys.append(keys)
117 globalkeys = gears.table.join(globalkeys, keys)
120 function utils.has_battery()
121 return utils.is_dir("/sys/class/power_supply/BAT0")