· 8 years ago · Jan 26, 2018, 09:32 AM
1------------ MY AWESOME STUFF - Ã…SMUND ERVIK
2------------ NOTE THAT THIS PASTE CONTAINS SEVERAL FILES. THERE ARE TWO SHORT ONES AT THE END.
3
4------------ START OF RC.LUA
5-- Standard awesome library
6require("awful")
7require("awful.autofocus")
8require("awful.rules")
9-- Theme handling library
10require("beautiful")
11-- Notification library
12require("naughty")
13-- Widget library
14require("vicious")
15-- Expose effect library
16require("revelation")
17-- Calendar widget
18require("calendar2")
19-- Facebook widget
20--require("facebook")
21--Battery time on widget
22require("battime")
23
24-- {{{ Variable definitions
25-- Themes define colours, icons, and wallpapers
26beautiful.init("/home/asmund/.config/awesome/themes/default/theme.lua")
27
28-- This is used later as the default terminal and editor to run.
29terminal = "urxvt"
30editor = "vim"
31editor_cmd = terminal .. " -e " .. editor
32
33-- Default modkey.
34-- Usually, Mod4 is the key with a logo between Control and Alt.
35-- If you do not like this or do not have such a key,
36-- I suggest you to remap Mod4 to another key using xmodmap or other tools.
37-- However, you can use another modifier like Mod1, but it may interact with others.
38modkey = "Mod4"
39
40-- Table of layouts to cover with awful.layout.inc, order matters.
41layouts =
42{
43 awful.layout.suit.tile,
44 awful.layout.suit.tile.left,
45 awful.layout.suit.tile.bottom,
46 awful.layout.suit.tile.top,
47 awful.layout.suit.fair,
48 awful.layout.suit.fair.horizontal,
49 awful.layout.suit.max,
50 awful.layout.suit.max.fullscreen,
51 awful.layout.suit.magnifier,
52 awful.layout.suit.floating
53}
54-- }}}
55
56-- {{{ Tags
57-- Define a tag table which hold all screen tags.
58tags = {
59 names = {"term", "web", 3, 4, 5, 6, 7, 8, 9}, -- Edit this to your pleasing
60 layout = {layouts[3], layouts[7], layouts[1], layouts[1], layouts[1], layouts[1], layouts[1], layouts[1], layouts[1]}
61}
62for s = 1, screen.count() do
63 -- Each screen has its own tag table.
64 tags[s] = awful.tag(tags.names, s, tags.layout)
65end
66-- }}}
67
68-- {{{ Menu
69-- Create a laucher widget and a main menu
70myawesomemenu = {
71 { "manual", terminal .. " -e man awesome" },
72 { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
73 { "restart", awesome.restart },
74 { "quit", awesome.quit }
75}
76
77myawesomeinternet = {
78 { "Spotify", "wine C:\Programfiler\Spotify\spotify.exe"},
79 { "Firefox", "firefox"},
80 { "Skype", "skype"}
81}
82
83myawesomepower = {
84 { "Suspend", "sudo pm-suspend"},
85 { "Hibernate", "sudo pm-hibernate"},
86 { "Reboot", "sudo reboot"},
87 { "Shutdown", "sudo shutdown -h now"}
88}
89
90mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
91{ "internet", myawesomeinternet},
92{ "power", myawesomepower},
93 { "open terminal", terminal }
94 }
95 })
96
97mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
98 menu = mymainmenu })
99-- }}}
100
101-- Separators
102spacer = widget({ type = 'textbox'})
103separator = widget({ type = 'textbox'})
104spacer.text = ' '
105separator.text = '|'
106
107-- {{{ Wibox
108
109-- Baticon (in case of low bats)
110baticon = widget({type = 'imagebox'})
111baticon.image = image("/home/asmund/.config/awesome/icons/bat.png")
112batwidget = widget({type = 'textbox'})
113vicious.register(batwidget, vicious.widgets.bat, "$1$2%", 31, "BAT1")
114-- Add remaining time when on AC power
115battime.addBatTimeWidget(batwidget)
116
117-- Wifiwidget
118wifiicon = widget({type = 'imagebox'})
119wifiicon.image = image("/home/asmund/.config/awesome/icons/wifi.png")
120wifiwidget = widget({type = 'textbox'})
121vicious.register(wifiwidget, vicious.widgets.wifi, "${ssid} ${link}%", 5, "wlan0")
122
123-- Cpuwidget
124cpuicon = widget({type = 'imagebox'})
125cpuicon.image = image("/home/asmund/.config/awesome/icons/cpu.png")
126cpuwidget = widget({type = 'textbox'})
127vicious.register(cpuwidget, vicious.widgets.cpu, " $1%", 2)
128
129-- Clock icon
130clockicon = widget({type ='imagebox'})
131clockicon.image = image("/home/asmund/.config/awesome/icons/time.png")
132
133-- Mail icon
134mailicon = widget({type ='imagebox'})
135mailicon.image = image("/home/asmund/.config/awesome/icons/email.png")
136
137-- Mail widget
138mailwidget = widget({ type = "textbox", align = "right" })
139mailwidget.text = "" --Updated by signal later, see mailtimer.
140
141-- Facebook icon
142fbicon = widget({type ='imagebox'})
143fbicon.image = image("/home/asmund/.config/awesome/icons/facebook.png")
144
145-- Facebook widget
146fbwidget = widget({ type = "textbox", align = "right" })
147fbwidget.text = "" --Updated by signal later, see fbtimer.
148
149-- Add mouseover display of facebook
150--facebook.addFbToWidget(fbwidget)
151
152-- Create a textclock widget
153mytextclock = awful.widget.textclock({ align = "right" }, "%H:%M")
154
155-- Add calendar functionality on clock mouseover
156calendar2.addCalendarToWidget(mytextclock, "<span color='green'>%s</span>")
157
158--Widget that displays title of current Spotify song
159spotifytitle = widget({type = 'textbox'})
160spotifytitle.text = "" --This will be updated by a signal later, see spotimer.
161
162-- Create a systray
163mysystray = widget({ type = "systray" })
164
165-- Create a wibox for each screen and add it
166mywibox = {}
167mypromptbox = {}
168mylayoutbox = {}
169mytaglist = {}
170mytaglist.buttons = awful.util.table.join(
171 awful.button({ }, 1, awful.tag.viewonly),
172 awful.button({ modkey }, 1, awful.client.movetotag),
173 awful.button({ }, 3, awful.tag.viewtoggle),
174 awful.button({ modkey }, 3, awful.client.toggletag),
175 awful.button({ }, 4, awful.tag.viewnext),
176 awful.button({ }, 5, awful.tag.viewprev)
177 )
178mytasklist = {}
179mytasklist.buttons = awful.util.table.join(
180 awful.button({ }, 1, function (c)
181 if not c:isvisible() then
182 awful.tag.viewonly(c:tags()[1])
183 end
184 client.focus = c
185 c:raise()
186 end),
187 awful.button({ }, 3, function ()
188 if instance then
189 instance:hide()
190 instance = nil
191 else
192 instance = awful.menu.clients({ width=250 })
193 end
194 end),
195 awful.button({ }, 4, function ()
196 awful.client.focus.byidx(1)
197 if client.focus then client.focus:raise() end
198 end),
199 awful.button({ }, 5, function ()
200 awful.client.focus.byidx(-1)
201 if client.focus then client.focus:raise() end
202 end))
203
204for s = 1, screen.count() do
205 -- Create a promptbox for each screen
206 mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
207 -- Create an imagebox widget which will contains an icon indicating which layout we're using.
208 -- We need one layoutbox per screen.
209 mylayoutbox[s] = awful.widget.layoutbox(s)
210 mylayoutbox[s]:buttons(awful.util.table.join(
211 awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
212 awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
213 awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
214 awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
215 -- Create a taglist widget
216 mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
217
218 -- Create a tasklist widget
219 mytasklist[s] = awful.widget.tasklist(function(c)
220 return awful.widget.tasklist.label.currenttags(c, s)
221 end, mytasklist.buttons)
222
223 -- Create the wibox
224 mywibox[s] = awful.wibox({ position = "top", screen = s })
225 -- Add widgets to the wibox - order matters
226 mywibox[s].widgets = {
227 {
228 mylauncher,
229 mytaglist[s],
230 mypromptbox[s],
231 layout = awful.widget.layout.horizontal.leftright
232 },
233 mylayoutbox[s],
234 mytextclock,
235 spacer, clockicon,
236 spacer, wifiwidget, spacer, wifiicon,
237 spacer, batwidget, spacer, baticon,
238 spacer, mailwidget, spacer, mailicon,
239 spacer, fbwidget, spacer, fbicon,
240 spacer, cpuwidget, spacer, cpuicon,
241 spacer, spotifytitle,
242 s == 1 and mysystray or nil,
243 mytasklist[s],
244 layout = awful.widget.layout.horizontal.rightleft
245 }
246end
247-- }}}
248
249-- {{{ Mouse bindings
250root.buttons(awful.util.table.join(
251 awful.button({ }, 3, function () mymainmenu:toggle() end),
252 awful.button({ }, 4, awful.tag.viewnext),
253 awful.button({ }, 5, awful.tag.viewprev)
254))
255-- }}}
256
257-- {{{ Key bindings
258globalkeys = awful.util.table.join(
259 awful.key({ modkey, }, "Left", awful.tag.viewprev ),
260 awful.key({ modkey, }, "Right", awful.tag.viewnext ),
261 awful.key({ modkey, }, "Escape", awful.tag.history.restore),
262
263 awful.key({ modkey, }, "j",
264 function ()
265 awful.client.focus.byidx( 1)
266 if client.focus then client.focus:raise() end
267 end),
268 awful.key({ modkey, }, "k",
269 function ()
270 awful.client.focus.byidx(-1)
271 if client.focus then client.focus:raise() end
272 end),
273 awful.key({ modkey, }, "w", function () mymainmenu:show(true) end),
274
275 -- Layout manipulation
276 awful.key({ modkey, }, "e", revelation.revelation),
277 awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
278 awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
279 awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
280 awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
281 awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
282 awful.key({ modkey, }, "Tab",
283 function ()
284 awful.client.focus.history.previous()
285 if client.focus then
286 client.focus:raise()
287 end
288 end),
289
290 -- Standard program
291 awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
292 awful.key({ modkey, "Control" }, "r", awesome.restart),
293 awful.key({ modkey, "Shift" }, "q", awesome.quit),
294
295 awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
296 awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
297 awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
298 awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
299 awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
300 awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
301 awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
302 awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
303 -- Launch an alternate Mutt window in read-only mode (for viewing other emails)
304 awful.key({ modkey, }, "m", function () awful.util.spawn(mailreader) end),
305 -- Shutdown hotkey
306 awful.key({ modkey, }, "p", function () awful.util.spawn("sudo shutdown -h now") end),
307
308 -- Prompt
309 awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
310
311 awful.key({ modkey }, "x",
312 function ()
313 awful.prompt.run({ prompt = "Run Lua code: " },
314 mypromptbox[mouse.screen].widget,
315 awful.util.eval, nil,
316 awful.util.getdir("cache") .. "/history_eval")
317 end)
318)
319
320clientkeys = awful.util.table.join(
321 awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
322 awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
323 awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
324 awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
325 awful.key({ modkey, }, "o", awful.client.movetoscreen ),
326 awful.key({ modkey, "Shift" }, "r", function (c) c:redraw() end),
327 awful.key({ modkey, }, "n", function (c) c.minimized = not c.minimized end),
328 awful.key({ modkey, }, "m",
329 function (c)
330 c.maximized_horizontal = not c.maximized_horizontal
331 c.maximized_vertical = not c.maximized_vertical
332 end)
333)
334
335-- Compute the maximum number of digit we need, limited to 9
336keynumber = 0
337for s = 1, screen.count() do
338 keynumber = math.min(9, math.max(#tags[s], keynumber));
339end
340
341-- Bind all key numbers to tags.
342-- Be careful: we use keycodes to make it works on any keyboard layout.
343-- This should map on the top row of your keyboard, usually 1 to 9.
344for i = 1, keynumber do
345 globalkeys = awful.util.table.join(globalkeys,
346 awful.key({ modkey }, "#" .. i + 9,
347 function ()
348 local screen = mouse.screen
349 if tags[screen][i] then
350 awful.tag.viewonly(tags[screen][i])
351 end
352 end),
353 awful.key({ modkey, "Control" }, "#" .. i + 9,
354 function ()
355 local screen = mouse.screen
356 if tags[screen][i] then
357 awful.tag.viewtoggle(tags[screen][i])
358 end
359 end),
360 awful.key({ modkey, "Shift" }, "#" .. i + 9,
361 function ()
362 if client.focus and tags[client.focus.screen][i] then
363 awful.client.movetotag(tags[client.focus.screen][i])
364 end
365 end),
366 awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
367 function ()
368 if client.focus and tags[client.focus.screen][i] then
369 awful.client.toggletag(tags[client.focus.screen][i])
370 end
371 end))
372end
373
374clientbuttons = awful.util.table.join(
375 awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
376 awful.button({ modkey }, 1, awful.mouse.client.move),
377 awful.button({ modkey }, 3, awful.mouse.client.resize))
378
379-- Set keys
380root.keys(globalkeys)
381-- }}}
382
383-- {{{ Rules
384awful.rules.rules = {
385 -- All clients will match this rule.
386 { rule = { },
387 properties = { border_width = beautiful.border_width,
388 border_color = beautiful.border_normal,
389 focus = true,
390 keys = clientkeys,
391 buttons = clientbuttons } },
392 { rule = { class = "MPlayer" },
393 properties = { floating = true } },
394 { rule = { class = "pinentry" },
395 properties = { floating = true } },
396 { rule = { class = "gimp" },
397 properties = { floating = true } },
398 -- Set Firefox to always map on tags number 2 of screen 1.
399 { rule = { class = "firefox" },
400 properties = { tag = tags[1][2] } },
401 -- Set urxvt to always map on tag number 1 of screen 1.
402 { rule = {class = "urxvt"},
403 properties = { tag = tags[1][1] } }
404}
405-- }}}
406
407-- {{{ Signals
408-- Signal function to execute when a new client appears.
409client.add_signal("manage", function (c, startup)
410 -- Add a titlebar
411 -- awful.titlebar.add(c, { modkey = modkey })
412
413 -- Enable sloppy focus
414 c:add_signal("mouse::enter", function(c)
415 if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
416 and awful.client.focus.filter(c) then
417 client.focus = c
418 end
419 end)
420
421 if not startup then
422 -- Set the windows at the slave,
423 -- i.e. put it at the end of others instead of setting it master.
424 -- awful.client.setslave(c)
425
426 -- Put windows in a smart way, only if they does not set an initial position.
427 if not c.size_hints.user_position and not c.size_hints.program_position then
428 awful.placement.no_overlap(c)
429 awful.placement.no_offscreen(c)
430 end
431 end
432end)
433
434-- This gives Spotify its current playing song.
435-- Timer signals at timeout to update the title.
436spotimer = timer ({ timeout = 4 })
437spotimer:add_signal("timeout", function()
438 os.execute("getify > /home/asmund/.config/awesome/spotify.tmp")
439 local f = io.open("/home/asmund/.config/awesome/spotify.tmp")
440 local l = ""
441 if f ~= nil then
442 l = f:read()
443 end
444 if l == nil then
445 l = ''
446 elseif string.len(l) >= 25 then
447 l = string.sub(l, 1, 22).."..." --We chop the string if it is too long.
448 end
449 f:close()
450 spotifytitle.text = l
451end)
452spotimer:start()
453
454-- Note: you want your timeouts to be different primes, then they wont overlap often.
455mailtimer = timer ({ timeout = 13 })
456mailtimer:add_signal("timeout", function()
457 local f = io.open("/home/asmund/awesome/mail.tmp")
458 local l = nil
459 if f ~= nil then
460 l = f:read() -- read output of command
461 else
462 l = ""
463 end
464 f:close()
465 mailwidget.text = l
466 os.execute("/home/asmund/awesome/mailcheck.py > /home/asmund/awesome/mail.tmp &")
467end)
468mailtimer:start()
469
470-- This automounts the NTNU folder if internet is available.
471--sshfstimer = timer({ timeout = 101 })
472--sshfstimer:add_signal("timeout", function()
473-- os.execute("fsNTNUwrap")
474--end)
475--sshfstimer:start()
476
477client.add_signal("focus", function(c) c.border_color = beautiful.border_focus c.opacity = 1 end)
478client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal c.opacity = 0.7 end)
479-- }}}
480
481---------------- END OF RC.LUA
482
483---------------- START OF MAILCHECK.PY
484#!/usr/bin/python
485# This script checks if you have any unread mail. Change the mail address and password.
486# This script should be stored along with rc.lua and chmod +x
487
488import imaplib
489
490#first field is imap server, second - port (993 for gmail SSL IMAP)
491M=imaplib.IMAP4_SSL("imap.gmail.com", 993)
492#first field is imap login (gmail uses login with domain and '@' character),second - password
493M.login("aaervik@gmail.com","YOURPASSWORD") # Replace with your password
494
495status, counts = M.status("Inbox","(MESSAGES UNSEEN)")
496
497
498unread = counts[0].split()[4][:-1]
499unint = int(unread)
500if unint == 0:
501 print("0")
502else:
503 #red color when you have unseen mail
504 print ("<span color='red'>",unint,"</span>",sep="")
505
506M.logout()
507
508---------------- END OF MAILCHECK.PY
509
510---------------- START OF GETIFY
511#! /usr/bin/python2.7
512# This script pulls the current-playing title from Spotify. Requires "xwininfo" and "xprop".
513# This script should be in your path and chmod +x
514
515#Importing stuff
516from subprocess import Popen, PIPE
517
518
519cmd = "xwininfo -children -root | awk '/spotify/{print $1}'" #Get window ID of spotify
520p = Popen(cmd, shell=True, stdout=PIPE)
521p.wait()
522wid = p.communicate()[0] #We save the ID
523id = wid.split()
524pid = '' #Make sure pid survives
525testname = '' #This also
526for l in id: #Sometimes a 'ghost' spotify window exists. Then id is a list, and for l in id,
527 cmd = 'xprop -id ' + l + ' | grep -i "WM_NAME(COMPOUND_TEXT)"' #We check if this l is the correct one.
528 #Also, we convert to UTF-8 to avoid errors.
529 p = Popen(cmd, shell=True, stdout=PIPE)
530 p.wait()
531 testname = p.communicate()[0]
532 if testname != '': #If the title is not blank, the current element is the correct one. Then we set
533 pid = l
534 break
535t = testname[36:] #We remove the gibberish that xprop gives us
536out = t.split('"')[0] #We remove the final " if we got the title
537if out != '':
538 tempout = unicode( out, "utf-8" )
539 out = tempout.encode( "utf-8" )
540 print(out)
541---------------- END OF GETIFY
542
543---------------- START OF