forked from koniu/awesome-configs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrc.lua
1330 lines (1219 loc) · 53.3 KB
/
rc.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--{{{ requires
require("dbg")
require("awful")
require("awful.autofocus")
require("beautiful")
require("naughty")
require("shifty")
require("handy")
require("wicked")
require("inotify")
require("obvious.popup_run_prompt")
dofile("/home/koniu/.config/awesome/functions.lua")
--}}}
--{{{ vars
--{{{ vars / common
modkey = "Mod4"
browser = 'x-www-browser '
theme_path = "/home/koniu/.config/awesome/theme.dark.master.lua"
icon_path = "/home/koniu/.config/awesome/icons/"
beautiful.init(theme_path)
if screen.count() == 2 then LCD = 2 else LCD = 1 end
layouts =
{
awful.layout.suit.max,
awful.layout.suit.tile,
awful.layout.suit.tile.bottom,
awful.layout.suit.fair,
awful.layout.suit.fair.horizontal,
awful.layout.suit.floating,
awful.layout.suit.max.fullscreen,
}
--custom
config = {}
config.terminal = "urxvtc"
-- step for scrolling
config.step = 15
-- screen offset it scrolls within
config.scroll_offset = 2
-- some shortcuts
join = awful.util.table.join
doc = awful.doc
--}}}
--{{{ vars / handy
handy.combo_subst = {
["(%u)"] = function(m) return string.lower(m) end,
control = "ctl",
mod1 = "alt",
mod4 = "win",
mod5 = "ralt",
XF86 = "x",
forward = "fwd",
}
handy.combo_ignore_groups = {
"1. global actions" ,
"default"
}
--}}}
--{{{ vars / shifty
--{{{ vars / shifty / config.tags
shifty.config.tags = {
["sys"] = { position = 0, exclusive = true, mwfact = 0.75307, screen = LCD, layout = "tilebottom" },
["jack"] = { position = 0, exclusive = true, mwfact = 0.85, nmaster = 1, screen = LCD, layout = "tilebottom" },
["term"] = { position = 2, exclusive = true, screen = LCD, layout = 'tilebottom' },
["www"] = { position = 3, exclusive = true, screen = LCD },
["fb"] = { position = 9, exclusive = true, layout = "tilebottom", mwfact=0.85 },
["dir"] = { rel_index = 1, exclusive = false },
["gq"] = { rel_index = 1, exclusive = true },
["vid"] = { rel_index = 1, exclusive = true },
["pdf"] = { rel_index = 1, exclusive = true },
["gimp"] = { spawn = "gimp", icon = "/usr/share/icons/hicolor/16x16/apps/gimp.png",
layout = "max", icon_only = true, sweep_delay = 2, exclusive = true },
["xev"] = { rel_index = 0, spawn = "urxvtc -title 'Event Tester' -name xev -e sh -c 'xev -id $WINDOWID'" },
["live"] = { icon = "/home/koniu/live.png", layout = "floating", sweep_delay = 2, icon_only = false },
["im"] = { position = 1, spawn = "urxvtc -title IRC -name irc -e screen -t irc -S irc -R irssi" },
["tetris"] = { rel_index = 0, spawn = "urxvtc -font '-*-*-*-*-*-*-*-240-*-*-*-*-*-2' -name tetris -e tetris" },
["X"] = { rel_index = 1, spawn = "awtester", layout = awful.layout.suit.tile.top, mwfact = 0.75 },
}
--}}}
--{{{ vars / shifty / config.apps
shifty.config.apps = {
-- tag matches
{ match = { "tail", "^top", "fping", "mtr", "htop", "iwconfig", "Wicd", "apt"
}, tag = "sys", },
{ match = { "urxvt" }, tag = "term", slave = true },
{ match = { "^mc$" }, tag = "dir", opacity = 0.8 },
{ match = { "Wine" }, tag = "wine", },
{ match = { "Ardour.*", "Jamin", }, tag = "ardour", },
{ match = { "Gmpc", }, tag = "mpd", },
{ match = { "[Mm]player", }, tag = "vid", },
{ match = { "^Acroread.*", "^Evince$" }, tag = "pdf", },
{ match = { "^irc$", }, tag = "im", },
{ match = { "Deluge", "nicotine", "Tucan.py", "^jd.Main$"
}, tag = "dl" },
-- bristol
{ match = { "^BasicWin$", }, tag = "bristol", float = 1 },
-- htop
{ match = { "^htop$", },
keys = join(remap({}, "Delete", {75,36}),
remap({}, "period", {{50,60},116,36}),
remap({}, "comma", {{50,59},111,36}))
},
-- gajim
{ match = { "^Gajim", }, tag = "im", },
{ match = { "^messages$", }, nopopup = true, slave = true, border_width = 0},
{ match = { "^roster$", }, float = true, geometry = { 0,34,186,734 },
dockable = true, struts = { left = 186 },
skip_taskbar = true, border_width = 0, nofocus = true,
props = { skip_focus = true } },
-- foobar2000
{ match = { "foobar2000.exe", }, tag = "fb", nopopup = 1, },
{ match = { "^Playlist Search$", "^ReplayGain Scan", "^Connecting to discogs$", "^Moving Files$",
"^Converting.*", "^Updating album/artist art", "^Copying Files$", "^Updating Files$",
"^Spectrum$", "^Spectrogram$" },
float = false, slave = 1, nofocus = 1, nopopup = 1 },
-- awtester
{ match = { "^awtester$", }, tag = "X", float = false },
{ match = { "^awtesterlog$", }, tag = "X", slave = true, nofocus = true,
border_width = 0 },
-- popterm (aka scratchpad)
{ match = { "popterm" },
intrusive = true, opacity = 0.8, float = true, sticky = true, ontop = true,
geometry = { 0, 568, 1024, 200 }, hidden = false, skip_taskbar = true,
startup = { hidden = true }
},
-- ableton live
{ match = { "^Live$", }, tag = "live", nopopup = true,
geometry = { 0, 34, 1400, 1000 }, },
-- www browsers
{ match = { "Iceweasel.*", "Firefox.*", "^Chrome$", "^x.www.browser$", "^sensible.browser$", "^Minefield$" },
tag = "www", },
-- qjackctl tweaks
{ match = { "Patchage" }, tag = "jack", props = { killhide = 1 }, },
{ match = { "jackctl" }, tag = "jack", slave = true, },
{ match = { "Informat.*CK Audio Connection Kit" }, kill = true, },
{ match = { "qjackctlMessagesForm",
"Error.*Connection Kit" }, nopopup = true, },
{ match = { "qjackctlMainForm", }, wfact = 0.5 },
-- gimp
{ match = { "Gimp", }, tag = "gimp",
keys = join(
awful.key({ "Mod1" }, "b", function(c) local a = getclient("role", "gimp-toolbox")
if a then a.hidden = not a.hidden end
end, nil, "Toggle toolbox"),
awful.key({ "Mod1" }, "v", function(c) local a = getclient("role", "gimp-dock")
if a then a.hidden = not a.hidden end
end, nil, "Toggle dock")) },
{ match = { "^gimp.toolbox$", }, struts = { right=172}, skip_taskbar = true,
geometry = {852,34,172,734}, slave = true,
border_width = 0 },
{ match = { "^gimp.dock$", }, struts = { left=170}, skip_taskbar = true,
geometry = {0,34,170,734}, slave = true,
border_width = 0 },
-- geeqie
{ match = { "^Geeqie$" }, tag = "gq" },
{ match = { "Full screen...Geeqie" }, intrusive = true, border_width = 0, fullscreen = 1, ontop=true },
{ match = { "Tools...Geeqie" },
keys = join(awful.key({}, "Escape", function(c) getclient("id", c.group_id + 2):kill() end)) },
{ match = { "^gimp%-image%-window$" }, nopopup = true, slave = true },
-- various tweaks
{ match = { "^JACK Rack MIDI Controls$" }, float = false, },
{ match = { "sqlitebrowser" }, slave = true, float = false, tag = "sql" },
{ match = { "^xev$" }, skip_taskbar = true, tag = "xev", opacity =.8 },
-- menu
{ match = { "^menu$", }, skip_taskbar = true, dockable = true,
ontop = true, opacity = 0.9 },
-- slaves
{ match = { "xmag","^Downloads$", "ufraw", "qjackctl", "fping", "watch",
}, slave = true, },
-- floats
{ match = { "recordMyDesktop", "Skype", "QQQjackctl", "MPlayer", "xmag", "gcolor2", "javax.swing",
"^Install user style$"
}, float = true, },
-- nopopup
{ match = { "^Downloads$",
}, nofocus = true, },
-- intruders
{ match = { "^dialog$", "xmag", "gcolor2", "^Download$", "^menu$",
}, intrusive = true, },
-- all
{ match = { "" },
honorsizehints = false,
buttons = join(
awful.button({ }, 1, function (c) client.focus = c; c:raise() end, nil, "Focus client"),
awful.button({ "Mod1" }, 1, awful.mouse.client.move, nil, "Move client"),
awful.button({ "Mod1" }, 3, awful.mouse.client.resize, nil, "Resize client" )
),
},
}
--}}}
--{{{ vars / shifty / gittags(tm)
--{{{ vars / shifty / gittags(tm) / config
local gittags = {
[ "d:awsm" ] = { push = "push mg +", main = "zsh", dir = "/home/koniu/awesome", commit = "-a -s",
url = "http://git.naquadah.org/?p=awesome.git;a=shortlog;h=refs/heads/master" },
[ "d:shifty" ] = { push = "push mg +", main = "vim lib/shifty.lua.in", dir = "/home/koniu/shifty", commit = "-a -s",
url = "http://git.mercenariesguild.net/?p=awesome.git;a=shortlog;h=refs/heads/shifty-master" },
[ "d:conf" ] = { push = "push origin +", main = "vim rc.lua", dir = "/home/koniu/.config/awesome", commit = "-a",
url = "http://github.com/koniu/awesome-configs/commits/master/rc.lua" },
[ "d:obv" ] = { push = "", main = "zsh", dir = "/home/koniu/.config/awesome/obvious", commit = "-a -s",
url = "http://git.mercenariesguild.net/?p=obvious.git;a=shortlog;h=refs/heads/master" },
[ "d:vali" ] = { push = "", main = "zsh", dir = "/home/koniu/data/kit/git/validichro", commit = "-a",
url = "" },
}
--}}}
for n, v in pairs(gittags) do
--{{{ vars / shifty / gittags(tm) / commands
local spawn = "urxvtc -name "..n.."main -title '"..v.main.."' -cd "..v.dir.." -e "..v.main
local see_www = function() awful.tag.viewonly(shifty.name2tag("www")) end
local cmds = {
log = function() terminal("-font 6x10 -name "..n.."pop -hold -title '"..n.." git log' -cd "..v.dir.." -e git -p log --abbrev-commit --abbrev=8 --pretty=oneline") end,
diff = function() terminal("-font 6x10 -name "..n.."pop -hold -title '"..n.." git diff' -cd "..v.dir.." -e git -p diff --patch-with-stat") end,
pull = function() terminal("-name "..n.."pop -hold -title '"..n.." git pull' -cd "..v.dir.." -e git pull") end,
status = function() terminal("-name "..n.."pop -hold -title '"..n.." git status' -cd "..v.dir.." -e git status") end,
prompt = function() terminal("-name "..n.."cmd -title '"..n.." git prompt' -cd "..v.dir.." -e zsh") end,
commit = function() terminal("-name "..n.."cmd -hold -title '"..n.." git commit' -cd "..v.dir.." -e git commit "..v.commit) end,
gitweb = function() awful.util.spawn(browser..v.url.."'"); see_www(); end,
apidoc = function() awful.util.spawn(browser .. "http://awesome.naquadah.org/doc/api/"); see_www(); end,
push = function()
local br=awful.util.pread("cd "..v.dir.."; git branch --no-color 2> /dev/null | grep \\*")
br = br:sub(3, #br-1)
terminal("-name "..n.."pop -hold -title '"..n.." git push "..br.."' -cd "..v.dir.." -e git "..v.push..br)
end,
branch = function()
prompt.exec({
history = os.getenv("HOME") .. "/.cache/awesome/history_gittags-"..n,
args = {
fg_cursor = "#FF1CA9", bg_cursor = beautiful.bg_normal, ul_cursor="single",
selectall = true, prompt = "<span color='#FF1CA9'>Branch</span>: ",
},
run_function = function(line)
local txt = awful.util.pread("cd "..v.dir.."; git checkout "..line.." 2>&1")
local clr = "white"
if txt:find("^error") then
clr = "red"
elseif txt:find("^Switched") then
clr = "green"
end
naughty.notify{ text="<span color='"..clr.."'>"..txt:sub(1,#txt-1).."</span>" }
end,
completion_function = function (cmd, cur_pos, ncomp)
local branches = {}
local matches = {}
local g = io.popen("cd "..v.dir.."; git branch")
for line in g:lines() do table.insert(branches, line:sub(3, #line)) end
g:close()
if cur_pos ~= #cmd + 1 and cmd:sub(cur_pos, cur_pos) ~= " " then return cmd, cur_pos end
for i, j in ipairs(branches) do
if branches[i]:find("^" .. cmd:sub(1, cur_pos)) then
table.insert(matches, branches[i])
end
end
if #matches == 0 then return cmd, cur_pos end
while ncomp > #matches do ncomp = ncomp - #matches end
return matches[ncomp], cur_pos
end})
end
}
--}}}
--{{{ vars / shifty / gittags(tm) / tag settings + bindings
awful.doc.set_default({ group = "gittags(tm)" })
shifty.config.tags[n] = {
position = 9, exclusive = true, screen = LCD, layout = awful.layout.suit.tile.bottom, spawn = spawn, mwfact = 0.7,
keys = awful.util.table.join(
awful.key({ modkey }, "l", cmds.log, nil, "git log" ),
awful.key({ modkey }, "d", cmds.diff, nil, "git diff"),
awful.key({ modkey }, ".", cmds.push, nil, "git push"),
awful.key({ modkey }, ",", cmds.pull, nil, "git pull"),
awful.key({ modkey }, "c", cmds.commit, nil, "git commit"),
awful.key({ modkey }, "s", cmds.status, nil, "git status"),
awful.key({ modkey }, "w", cmds.gitweb, nil, "gitweb"),
awful.key({ modkey }, "a", cmds.apidoc, nil, "api reference"),
awful.key({ modkey }, "b", cmds.branch, nil, "git checkout"),
awful.key({ modkey }, "grave", cmds.prompt, nil, "cmdline")
),
}
awful.doc.set_default({ })
--}}}
--{{{ vars / shifty / gittags(tm) / client settings + bindings
awful.doc.set_default({ group = "gittags(tm) / client" })
-- match to tags
table.insert(shifty.config.apps,
{ match = { n.."main$", n.."cmd$", n.."pop$" }, tag = n })
-- slave/skip_taskbar popups and commandline
table.insert(shifty.config.apps,
{ match = { n.."cmd$", n.."pop$" }, slave = true, titlebar = true, skip_taskbar = true })
-- popups die on 'q'
table.insert(shifty.config.apps,
{ match = { n.."pop$" }, keys = join(awful.key({}, "q", function(c) c:kill() end, nil, "quit")), })
-- reload main window with mod+alt+l
table.insert(shifty.config.apps,
{ match = { n.."main$" }, keys = join(awful.key({"Mod1", modkey}, "l", function(c) c:kill(); awful.util.spawn(spawn) end, nil, "reload client")), })
-- reload commands on mod+alt+l
for m, f in pairs(cmds) do
table.insert(shifty.config.apps,
{ match = { n.." git "..m },
keys = join(awful.key({"Mod1", modkey}, "l", function(c) c:kill(); f() end, nil, "reload client")), })
end
awful.doc.set_default({ })
--}}}
end
--}}}
--{{{ vars / shifty / initialize
shifty.config.defaults = {
layout = "max",
leave_kills = false,
}
shifty.config.default_name = "?"
shifty.config.layouts = layouts
shifty.init()
--}}}
--}}}
--{{{ vars / naughty
naughty.config.spacing = 1
naughty.config.default_preset = {
font = 'Monospace 6.5',
border_width = 1,
margin = 5,
screen = LCD,
opacity = 0.95,
}
--}}}
--{{{ vars / widgets
config.widgets = {}
config.widgets.watchmount = { "/dev/sda2", "/media/", "/mnt/" }
config.widgets.autostart = {
default = "urxvtc -name mc -geometry 169x55 -e mc %f",
movies = "urxvtc -name mc -geometry 169x55 -e mc %f ~/data/tmp",
photo = "gq %f",
p6000 = "gq %f/dcim",
}
config.widgets.space = " "
config.widgets.wifi = "wlan1"
--}}}
--{{{ vars / audio
require("jackmix")
mixer = jackmix.new{
port = 1234,
host = "localhost",
step = 2,
state_file = "/home/koniu/.cache/mixer",
}
require("recorder")
rek = recorder.new{
backend = recorder.backends.rec,
style = recorder.styles.horizontal,
}
--}}}
--}}}
--{{{ prompts
prompt.presets = {
--{{{ prompts / defaults
default = {
position = "top",
width = 1, height = 34, border_width = 0, opacity = 0.9, margin = { top = 12, left = 12 },
slide = true, move_speed = 0.003, move_amount = 1, autoexec = 1
},
--}}}
--{{{ prompts / run
run = {
completion_function = awful.completion.shell,
run_function = function(s)
local rv = awful.util.spawn(s, true)
if rv then naughty.notify({ text = awful.util.escape(rv), timeout = 0, hover_timeout = 0.2 }) end
end,
history = os.getenv("HOME") .. "/.cache/awesome/history",
args = { prompt = "<span color='#CC8400'>Run</span>: ", fg_cursor = "#FFA500",
bg_cursor = beautiful.bg_normal, ul_cursor = "single", autoexec = 1},
},
--}}}
--{{{ prompts / lua
lua = {
completion_function = lua_completion,
run_function = function(s)
local r, msg = pcall(awful.util.eval, s)
if not r then naughty.notify({ text = awful.util.escape(msg), timeout = 0, hover_timeout = 0.2 }) end
end,
history = os.getenv("HOME") .. "/.cache/awesome/history_eval",
args = { prompt = "<span color = '#A7CC00'>Lua</span>: ", fg_cursor = "#D1FF00",
bg_cursor = beautiful.bg_normal, ul_cursor = "single", },
},
--}}}
--{{{ prompts / calc
calc = {
completion_function = lua_completion,
run_function = calculator,
history = os.getenv("HOME") .. "/.cache/awesome/history_calc",
args = { prompt = "<span color='#007478'>Calc</span>: ", fg_cursor = "#00A5AB",
bg_cursor = beautiful.bg_normal, ul_cursor = "single", selectall = true, },
},
--}}}
--{{{ prompts / dict
dict = {
completion_function = function() return false end,
run_function = dictionary,
history = os.getenv("HOME") .. "/.cache/awesome/history_dict",
args = { prompt = "<span color='#0073CC'>Dict</span>: ", fg_cursor = "#008DFA",
bg_cursor = beautiful.bg_normal, ul_cursor = "single", selectall = true, },
},
--}}}
--{{{ prompts / kill
kill = {
completion_function = kill_completion,
run_function = kill,
history = "",
args = { prompt = "<span color='#CC3F3F'>Kill</span>: ", fg_cursor = "#FF4F4F",
bg_cursor = beautiful.bg_normal, ul_cursor= "single", },
},
--}}}
--{{{ prompts / api
api = {
completion_function = lua_completion,
run_function = function(n) handy.get(loadstring("return " .. n)()) end,
history = os.getenv("HOME") .. "/.cache/awesome/help_search",
args = { prompt = "<span color='#CC3F7D'>Help</span>: ", fg_cursor = "#FF4F9B",
bg_cursor = beautiful.bg_normal, ul_cursor= "single", },
},
--}}}
}
--}}}
--{{{ widgets
--{{{ widgets / jack
--{{{ widgets / jack / functions
function jack_volume()
if type(mixer.state) == "number" then
return pad(math.ceil(mixer.state) .. "%",3)
else
return "<span color='#aa4444'>m </span>"
end
end
function jack_status()
local ps = psgrep({command = "^/usr/bin/jackd"})
local stat, vol
if not ps then
stat = "off"
vol = ""
elseif ps[1].command:find("dfirewire") or ps[1].command:find("dfreebob") then
stat = "fw"
vol = jack_volume()
elseif ps[1].command:find("dalsa") then
stat = "alsa"
vol = jack_volume()
end
return stat, vol
end
function jack_toggle(pre)
local state, vol = jack_status()
if pre == "alsa" or state == "off" or state == "fw" then
awful.util.spawn_with_shell("jackwrap -R -dalsa -r44100 -p512 -n3 -o0")
elseif pre == "fw" or state == "alsa" then
awful.util.spawn_with_shell("jackwrap -R -dfirewire -dhw:1 -r44100 -p512 -n3 -o0")
end
end
--}}}
jackwidget = widget({ type = 'textbox' })
jackwidget:buttons(join(
awful.button({}, 3, jack_toggle),
awful.button({}, 1, function() cli_toggle("patchage", "class", "Patchage") end)
))
--}}}
--{{{ widgets / wifi
function dump_autoap()
--awful.util.spawn_with_shell('curl -s http://10.6.6.1/user/autoap.htm > /tmp/.awesome.autoap')
end
function show_netpopup()
naughty.destroy(netpopup)
local iwconfig = awful.util.pread("/sbin/iwconfig " .. config.widgets.wifi)
local ifconfig = awful.util.pread("/sbin/ifconfig " .. config.widgets.wifi)
local route = awful.util.pread("/bin/ip route")
local iwgetid = awful.util.pread("/sbin/iwgetid -c")
local start, endd = iwconfig:find('".*"')
if not start or not endd then return end
local essid = iwconfig:sub(start+1, endd-1)
start, endd = iwconfig:find("Rate.* Mb/s")
if not start or not endd then return end
local rate = iwconfig:sub(start+5,endd-5)
local start, endd = ifconfig:find("inet addr:.* Bcast")
if not start or not endd then return end
local ip = ifconfig:sub(start+10, endd-5)
local start, endd = route:find("via %d+%.%d+%.%d+%.%d+ dev " .. config.widgets.wifi)
if not start or not endd then return end
local gw = route:sub(start+4,endd-9)
local start, endd = iwgetid:find("Channel:%d+")
if not start or not endd then return end
local channel = iwgetid:sub(start+8,endd)
local autoap = get_autoap()
netpopup = naughty.notify({ text = "<span color='#26241E'>essid: </span>" .. essid .. " (<span color='#26241E'>channel</span> " .. channel .. ", " .. rate .. " <span color='#26241E'>mbps</span>" .. ")\n" ..
((autoap and ("<span color='#26241E'>autoap essid: </span>" .. autoap.ap .. "\n")) or "") ..
-- ((autoap and ("<b>autoap gw: </b>" .. autoap.gw .. "\n")) or "" ) ..
((autoap and ("<span color='#26241E'>autoap loss: </span>" .. autoap.loss .. "\n")) or "" ) ..
"<span color='#26241E'>ip: </span>" .. ip .. "\n" ..
"<span color='#26241E'>gw: </span>" .. gw,
timeout = 5, hover_timeout = 0.2 })
end
function get_autoap()
local ap = ""
local f = io.open('/tmp/.awesome.autoap')
if not f then return end
local line = f:read("*a")
f:close()
if not line then return end
local aar, beg = line:find('<title>')
if not aar or not beg then return end
if line:sub(beg+32, beg+32) == 'S' then ap = "<span color=\"#FF602E\">searching...</span>"
elseif line:sub(beg+32,beg+32) == 'C' then
endd = line:find('</title>', beg)
ap = line:sub(beg+47,endd-2)
end
local start, endd = line:find("rescanning%. %d+%% packet loss")
if not start or not endd then return end
local loss = line:sub(start+12,endd-12)
if last_ap and ap ~= last_ap then naughty.notify({title = "AutoAP network", text = ap, timeout = 10})
last_ap = ap end
return { ap = ap, loss = loss, gw = gw}
end
local function get_wifi()
local v = ''
local a = io.open('/sys/class/net/'..config.widgets.wifi..'/wireless/link')
if not a then
netup = nil
return '<span color="#D9544C">off</span>'
end
v = math.floor(a:read() / 0.7)
a:close()
if v == 0 then
v = '<span color="#D9544C">down</span>'
netup = nil
else
v = string.format("%-4s", v .. "%")
netup = 1
end
return v
end
wifiwidget = widget({
type = 'textbox',
name = 'wifiwdget',
})
wifiwidget:buttons(join(
awful.button({}, 1, function () cli_toggle("wicd-gtk -n >& /dev/null", "class", "Wicd-client.py") end, nil, "show networks"),
awful.button({}, 2, show_netpopup, nil, "show autoap status"),
awful.button({}, 3, function () terminal("-name iwconfig -e watch -n1 /sbin/iwconfig "..config.widgets.wifi) end, nil, "show iwconfig")
))
wifiwidget:add_signal("mouse::enter", function() show_netpopup() end)
wifiwidget:add_signal("mouse::leave", function() naughty.destroy(netpopup) end)
awful.doc.set(wifiwidget, { class = "widgets", description = "This widget shows WIFI range", name = "wifiwidget" })
--}}}
--{{{ widgets / net
netwidget = widget({
type = 'textbox',
name = 'netwidget',
})
netwidget:buttons(join(
awful.button({}, 3, function () terminal("-name fping -e fping -le 10.6.6.1 google.com") end),
awful.button({}, 1, function () terminal("-name mtr -e mtr google.com") end)
))
netwidget.width = 100
--}}}
--{{{ widgets / cpugraph
cpugraphwidget = awful.widget.graph({ layout = awful.widget.layout.horizontal.leftright })
cpugraphwidget.widget:buttons(join(
awful.button({}, 3, function () terminal("-name top -e top") end),
awful.button({}, 1, function () terminal("-name htop -e htop --sort-key PERCENT_CPU") end)
))
cpugraphwidget:set_color('#252020')
cpugraphwidget:set_border_color('#000000')
cpugraphwidget:set_background_color('#000000')
cpugraphwidget:set_height(14)
cpugraphwidget:set_width(40)
cpugraphwidget:set_scale(false)
awful.widget.layout.margins[cpugraphwidget.widget] = { top = 1 }
awful.doc.set(cpugraphwidget, "cpugraph")
--}}}
--{{{ widgets / battery
batterywidget = widget({
type = 'textbox',
name = 'batterywidget',
align = 'right'
})
local function get_bat()
local color = 'orange'
local v = ''
local a = io.open('/sys/class/power_supply/BAT0/status')
if not a then return end
local status = a:read()
a:close()
local b = io.open('/sys/class/power_supply/BAT0/current_now')
local current = b:read()
b:close()
if status == "Full" or tonumber(current) == 0 then
v = ''
else
local a = io.open('/sys/class/power_supply/BAT0/energy_full')
local full = a:read()
a:close()
local a = io.open('/sys/class/power_supply/BAT0/energy_now')
local now = a:read()
a:close()
bat = math.floor(now*100/full)
if status == "Discharging" then
if bat < 11 then color="#D9544C"
elseif bat < 31 then color="#D9A24C"
else color="#D9CD4C"
end
elseif status == "Charging" then color="#ABD94C"
end
v = widgettext('BAT', bat .. '%',nil,color)
end
return v
end
--}}}
--{{{ widgets / memgraph
memgraphwidget = awful.widget.graph({ })
memgraphwidget.widget:buttons(join(
awful.button({}, 3, function () terminal("-name top -e top") end),
awful.button({}, 1, function () terminal("-name htop -e htop --sort-key PERCENT_MEM") end)
))
memgraphwidget:set_color('#0F120F')
memgraphwidget:set_border_color('#000000')
memgraphwidget:set_background_color('#000000')
memgraphwidget:set_height(14)
memgraphwidget:set_width(40)
memgraphwidget:set_scale(false)
awful.widget.layout.margins[memgraphwidget.widget] = { left = 1, top = 1, right = 2 }
function get_mem()
-- Return MEM usage values
local f = io.open('/proc/meminfo')
---- {{ Get data
for line in f:lines() do
line = splitbywhitespace(line)
if line[1] == 'MemTotal:' then
mem_total = math.floor(line[2]/1024)
elseif line[1] == 'MemFree:' then
free = math.floor(line[2]/1024)
elseif line[1] == 'Buffers:' then
buffers = math.floor(line[2]/1024)
elseif line[1] == 'Cached:' then
cached = math.floor(line[2]/1024)
end
end
f:close()
---- {{ Calculate percentage
mem_free=free+buffers+cached
mem_inuse=mem_total-mem_free
mem_usepercent = math.floor(mem_inuse/mem_total*100)
mem_cache_percent = math.floor((cached+buffers)/mem_total*100)
return {mem_usepercent, mem_cache_percent, mem_total, mem_free}
end
--}}}
--{{{ widgets / cputemp
cputempwidget = widget({
type = 'textbox',
name = 'cputempwidget',
align = 'left',
})
awful.widget.layout.margins[cputempwidget] = { left = 5 }
--cputempwidget.text = 'cpu'
local function get_cputemp()
local f = io.open('/sys/class/hwmon/hwmon1/device/temp1_input')
local v = f:read() / 1000
f:close()
return v
end
--}}}
--{{{ widgets / fan
fanwidget = widget({
type = 'textbox',
name = 'fanwidget',
align = 'left',
})
local function get_fan()
local f = io.open('/sys/class/hwmon/hwmon1/device/fan1_input')
local v = f:read()
f:close()
return v
end
--}}}
--{{{ widgets / mounts
function get_mounts()
local v = {}
local f = io.open('/tmp/.awesome.df')
if not f then return end
local l = f:lines()
for line in l do
for p,q in pairs(config.widgets.watchmount) do
if line:find(q) ~= nil then
local tmp = {}
for id in line:gmatch("%S+") do table.insert(tmp,id) end
if #tmp > 6 then tmp[6]=tmp[6]..' '..tmp[7] end -- hack: space in mountpoint
table.insert(v,{tmp[6], tmp[4], q})
end
end
end
f:close()
return v
end
function dump_mounts()
os.execute('df -h > /tmp/.awesome.df &')
end
function mountlist()
local w = { layout = awful.widget.layout.horizontal.leftright }
local function update()
local mnts = get_mounts()
if not mnts or #mnts == 0 then return end
local len = w.len or #w
-- Add more widgets
if len < #mnts then
for i = len + 1, #mnts do
w[i] = widget({ type = "textbox", align = "right" })
awful.doc.set(w[i], { name = "mountwidget", description = "Mount widget", class = "widgets" })
end
-- Remove widgets
elseif len > #mnts then
for i = #mnts + 1, len do
w[i] = nil
end
end
-- Update widgets text
for i,mnt in ipairs(mnts) do
local color
if tonumber(mnt[2]:sub(1,#mnt[2]-1)) < 200 and mnt[2]:sub(#mnt[2],#mnt[2]) == 'M' then
color = "#D9544C" else color = beautiful.widget_value
end
local tmp = {}
local esc=string.gsub(mnt[1],' ','\\ ')
w[i].text = mnt[1]:gsub(mnt[3],''):upper() ..
'<span color="' .. color .. '">' .. mnt[2] .. '</span>' ..
config.widgets.space
w[i]:buttons(join(
awful.button({}, 1,
function ()
local action
for m, spwn in pairs(config.widgets.autostart) do
if mnt[1]:lower():find(m) then
action = spwn
break
end
end
if not action then action = config.widgets.autostart.default end
action = action:gsub("%%f", esc)
awful.util.spawn_with_shell(action)
end, nil, "Open"),
awful.button({}, 2,
function ()
local action = config.widgets.autostart.default
action = action:gsub("%%f", esc)
awful.util.spawn_with_shell(action)
end, nil, "Browse"),
awful.button({}, 3,
function ()
local cli = client.get()
local t = "Volume in use:"
for i,c in ipairs(cli) do
if c.name:find(esc) then
end
end
awful.util.spawn("eject " .. esc, false)
awful.util.spawn("pumount " .. esc, false)
--awful.util.spawn("pumount -l " .. esc)
end, nil, "Unmount")
))
end
end
local t = timer({ timeout = 1 })
t:add_signal("timeout", update)
t:start()
update()
return w
end
mountwidget = mountlist()
--}}}
--{{{ widgets / apt
aptwidget = widget({ type = "textbox", name = "aptwidget", align="right"})
aptwidget:buttons(join(
awful.button({ }, 1, function () terminal("-name apt -geometry 169x55 -title aptitude -e sudo aptitude") end)
))
function get_apt()
local f = io.open('/tmp/.awesome.apt')
if not f then return end
local apt = f:read()
f:close()
if not apt then return end
if tonumber(apt) > 0 then
aptwidget.text = widgettext('APT', apt , nil, '#99C399' )
else
aptwidget.text = ''
end
end
function dump_apt()
os.execute("sudo apt-get upgrade -s | grep upgraded | tail -n1 | awk '{ print $1 }' > /tmp/.awesome.apt &")
end
--}}}
--{{{ widgets / clock
clockwidget = widget({ type = "textbox", })
awful.doc.set(clockwidget, { description = "System time", class = "widgets", name = "clockwidget" })
calendar = nil
local offset = 0
function remove_calendar()
if calendar ~= nil then
naughty.destroy(calendar)
calendar = nil
offset = 0
end
end
function showcalendar(inc_offset)
local save_offset = offset
remove_calendar()
if inc_offset == 666 then
offset = 0
else
offset = save_offset + inc_offset
end
local datespec = os.date("*t")
local date = datespec.year * 12 + datespec.month - 1 + offset
date = (date % 12 + 1) .. " " .. math.floor(date / 12)
cal = awful.util.pread("cal " .. date)
cal = string.gsub(cal, "^%s*(.-)%s*$", "%1")
cal = string.gsub(cal, "Mo Tu We Th Fr Sa Su", "<span color='#333028'>Mo Tu We Th Fr Sa Su</span>")
local day = pad(datespec.day, 2, " ")
if offset == 0 then cal = string.gsub(cal, "([\n ])(" .. day .. ")", "%1<span color='orange'>%2</span>") end
calendar = naughty.notify({
text = os.date("<b><span color=\"white\">%a, %d %B %Y</span></b>\n\n") .. cal,
timeout = 0, hover_timeout = 0.5, --height=130
})
end
clockwidget:buttons(join(
awful.button({ }, 1, function () showcalendar(-1) end, nil, "Show previous month"),
awful.button({ }, 2, function () showcalendar(666) end, nil, "Show current month"),
awful.button({ }, 3, function () showcalendar(1) end, nil, "Show next month"),
awful.button({ }, 4, function () showcalendar(-1) end, nil, "Show previous month"),
awful.button({ }, 5, function () showcalendar(1) end, nil, "Show next month")
))
clockwidget:add_signal("mouse::enter", function() showcalendar(0) end)
clockwidget:add_signal("mouse::leave", function() remove_calendar() end)
--}}}
--{{{ widgets / systray
mysystray = widget({ type = "systray", name = "mysystray", align = "right" })
--}}}
--{{{ widgets / layoutbox
mylayoutbox = {}
for s = 1, screen.count() do
mylayoutbox[s] = awful.widget.layoutbox(s, { })
mylayoutbox[s].image = img
mylayoutbox[s].resize = false
mylayoutbox[s]:buttons(join(
awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)
))
awful.widget.layout.margins[mylayoutbox[s]] = { top = 4, left = 2, right = 2 }
end
--}}}
--{{{ widgets / hook functions
--{{{ widgets / hook functions / 1s
function hook_1s()
local color,color2=''
cpugraphwidget:add_value(wicked.widgets.cpu()[1]/100)
local a = get_mem()
memgraphwidget:add_value(a[1] / 100)
cputempwidget.text = widgettext('CPU', get_cputemp() .. '°C')
fanwidget.text = widgettext('FAN', string.format("%-4s",get_fan()))
wifiwidget.text = widgettext('WIFI', get_wifi())
local stat,vol = jack_status()
if stat == "fw" or stat == "alsa" then stat = "<span color='#333333'>"..stat.." </span>" end
jackwidget.text = widgettext('JCK', (stat or "off") .. (vol or ""))
if netup then
local b = wicked.widgets.net()
if b['{'..config.widgets.wifi.. ' down_kb}'] > 0 then color = beautiful.widget_value; color = beautiful.widget_value else color = '#333333' end
if b['{'..config.widgets.wifi.. ' up_kb}'] > 0 then color2 = beautiful.widget_value else color2 = '#333333' end
netwidget.text = widgettext('NET', string.format('%3s <span color="#333333">/</span> %-3s', b['{'..config.widgets.wifi..' down_kb}'], b['{'..config.widgets.wifi.. ' up_kb}']), nil, color2)
else
netwidget.text = ''
end
clockwidget.text = (rec or "") .. "<span font_desc='' color='#cccccc'>" .. os.date("%H<span color='#999999'>:</span>%M<span color='#999999'>:</span>%S") .. "</span> "
end
hook_1s()
--}}}
--{{{ widgets / hook functions / 3s
function hook_3s ()
dump_mounts()
get_mounts()
end
hook_3s()
--}}}
--{{{ widgets / hook functions / 5s
function hook_5s ()
batterywidget.text = get_bat()
-- get_mail()
get_apt()
dump_autoap()
get_autoap()
end
hook_5s()
--}}}
--{{{ widgets / hook functions / 1m
function hook_1m ()
--dump_mail()
end
--}}}
--{{{ widgets / hook functions / 10m
function hook_10m ()
dump_apt()
end
--}}}
--}}}
--{{{ widgets / taglist
mytaglist = {}
mytaglist.buttons = join(
awful.button({ }, 1, awful.tag.viewonly, nil, "Switch to tag"),
awful.button({ modkey }, 1, awful.client.movetotag, nil, "Move client to tag"),
awful.button({ }, 3, awful.tag.viewtoggle, nil, "Toggle tag"),
awful.button({ modkey }, 3, awful.client.toggletag, nil, "Toggle client on tag"),