-
Notifications
You must be signed in to change notification settings - Fork 1
/
wicd.lua
68 lines (53 loc) · 1.38 KB
/
wicd.lua
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
local awful = require "awful"
local io = require "io"
local os = require "os"
local table = require "table"
local string = require "string"
local naughty = require "naughty"
local ipairs = ipairs
local beautiful = require("beautiful")
module("wicd")
local menu = nil
local terminal = terminal or os.getenv("TERMINAL") or "/usr/bin/urxvt"
connect = function(id)
awful.util.spawn("wicd-cli -yc --network " .. id)
end
connect_wired = function()
awful.util.spawn("wicd-cli -zc")
end
scan = function()
awful.util.spawn("wicd-cli -yS")
end
launch = function()
awful.util.spawn(terminal .. " -title WICD -e wicd-curses")
end
show = function()
local networks = {
{ "WIRED", nil },
{ " default", connect_wired},
{ "WIRELESS", scan }
}
local out = io.popen("wicd-cli -yl|tail -n+2 | cut -f4-")
local i = 0
for line in out:lines() do
table.insert(networks, {" " .. line, "wicd-cli -yc --network " .. i })
i = i + 1
end
out:close()
if #networks == 3 then
table.insert(networks, {" (none)", nil})
end
menu = awful.menu({items = networks, theme = {bg_normal = beautiful.widgets_menu_bg_normal, bg_focus = beautiful.widgets_menu_bg_focus}})
menu:show()
end
hide = function()
menu:hide()
menu = nil
end
toggle = function()
if menu == nil then
show()
else
hide()
end
end