-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc.lua
More file actions
80 lines (61 loc) · 1.66 KB
/
func.lua
File metadata and controls
80 lines (61 loc) · 1.66 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
--[[
Extra Awesome Window Manager Functions
by Brandon Thomas
* echelon@gmail/github
* http://posbl.org
]]--
-- Determine if battery is charging
-- FIXME: I don't know AWK very well
function batt_is_charging()
local device = '/org/freedesktop/UPower/devices/battery_' .. BATTERY_NAME
local cmd = 'upower -i '..device..' | grep state'
local fp = io.popen(cmd)
local result = fp:read()
if not result then
return false
end
for r in string.gmatch(result, 'discharging') do
return false
end
return true
end
-- Notification alert with text.
function alert(text)
awful.util.spawn_with_shell('notify-send "'..text..'"')
end
function alert2(text)
naughty.notify({ preset = naughty.config.presets.critical,
title = 'alert2',
text = text })
end
-- Get the cwd of the process pid
function process_get_cwd(pid)
local fp = io.popen("readlink /proc/" .. pid .. "/cwd")
return fp:read()
end
-- Get subprocess pid
-- (This is useful for getting the bash underlying urxvt)
function process_get_subproc_pid(pid)
local fp = io.popen("ps -ef | awk '$3=="..pid.." { print $2 }'")
return fp:read()
end
-- Open a terminal with at the same CWD as the current
-- terminal client
-- Optional arg: current client
-- (Install this function into client keybindings)
function open_terminal_same_cwd(client)
if not client then
client = awful.client.next(0)
end
if not client then
awful.util.spawn_with_shell(TERMINAL)
return
end
local pid = client.pid
local subpid = process_get_subproc_pid(pid)
if subpid then
pid = subpid
end
local cwd = process_get_cwd(pid)
awful.util.spawn_with_shell(TERMINAL_CWD .. " " .. cwd)
end