guest@dotshare [~/groups/wms/herbstluft] $ ls Idle-Event-in-Seven-Languages/ | cat

Idle Event in Seven Languages (scrot) (+1 likes)

epsi Jun 30, 2017 (wms/herbstluft)

autostart-unified.py(raw, dl)

SCROT

  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
#!/usr/bin/env python3
# ------------------------------------------------------------------
#
#     Description: unified config for herbstluftwm autostart
#     Created by: Epsi Nurwijayadi <epsi.nurwijayadi@gmail.com)
#
#     Source
#     https://github.com/epsi-rns/dotfiles/tree/master/herbstluftwm/python
#
#     Blog
#     http://epsi-rns.github.io/desktop/2017/05/01/herbstlustwm-modularized-overview.html
#     http://epsi-rns.github.io/desktop/2017/05/04/herbstlustwm-modularized-python.html
#
# ------------------------------------------------------------------

import os
from gmc import color

# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# config

tag_names = list(range(1, 10))
tag_keys  = list(range(1, 10)) + [0]

# keybindings

# if you have a super key you will be much happier with Mod set to Mod4
# Mod=Mod1    # Use alt as the main modifier
# Alt=Mod1
# Mod=Mod4    # Use the super key as the main modifier

# Modifier variables
s = 'Shift'
c = 'Control'
m = 'Mod4'
a = 'Mod1'

# resizing frames
resizestep = "0.05";

keybinds = {
  # session
    m+'-'+s+'-q' : 'quit',
    m+'-'+s+'-r' : 'reload',
    m+'-'+s+'-c' : 'close',

  # use your $TERMINAL with xterm as fallback
    m+'-Return'   : 'spawn ${TERMINAL:-xfce4-terminal}', 

  # epsi
    m+'-d'        : 'spawn dmenu_run_hlwm',
    m+'-'+s+'-d'     : 'spawn rofi -show run -opacity 90',
    m+'-'+s+'-x'     : 'spawn oblogout',

  # basic movement

  # focusing clients
    m+'-Left'     : 'focus left',
    m+'-Down'     : 'focus down',
    m+'-Up'       : 'focus up',
    m+'-Right'    : 'focus right',
    m+'-h'        : 'focus left',
    m+'-j'        : 'focus down',
    m+'-k'        : 'focus up',
    m+'-l'        : 'focus right',

  # moving clients
    m+'-'+s+'-Left'  : 'shift left',
    m+'-'+s+'-Down'  : 'shift down',
    m+'-'+s+'-Up'    : 'shift up',
    m+'-'+s+'-Right' : 'shift right',
    m+'-'+s+'-h'     : 'shift left',
    m+'-'+s+'-j'     : 'shift down',
    m+'-'+s+'-k'     : 'shift up',
    m+'-'+s+'-l'     : 'shift right',
    
  # splitting frames
  # create an empty frame at the specified direction
    m+'-u'        : 'split   bottom  0.5',
    m+'-o'        : 'split   right   0.5',
  # let the current frame explode into subframes
    m+'-'+c+'-space' : 'split explode',

  # resizing frames
    m+'-'+c+'-h'     : 'resize left  +' + resizestep,
    m+'-'+c+'-j'     : 'resize down  +' + resizestep,
    m+'-'+c+'-k'     : 'resize up    +' + resizestep,
    m+'-'+c+'-l'     : 'resize right +' + resizestep,
    m+'-'+c+'-Left'  : 'resize left  +' + resizestep,
    m+'-'+c+'-Down'  : 'resize down  +' + resizestep,
    m+'-'+c+'-Up'    : 'resize up    +' + resizestep,
    m+'-'+c+'-Right' : 'resize right +' + resizestep,
    
    # MPC
    m+'-'+a+'-h'     : 'spawn mpc toggle',
    m+'-'+a+'-t'     : 'spawn mpc prev',
    m+'-'+a+'-n'     : 'spawn mpc next'
}

# tags

tagskeybinds = {
  # cycle through tags
    m+'-period'   : 'use_index +1 --skip-visible',
    m+'-comma'    : 'use_index -1 --skip-visible',

  # layouting
    m+'-r'        : 'remove',
    m+'-s'        : 'floating toggle',
    m+'-f'        : 'fullscreen toggle',
    m+'-p'        : 'pseudotile toggle',

  # focus
    m+'-BackSpace' : 'cycle_monitor',
    m+'-Tab'       : 'cycle_all +1',
    m+'-'+s+'-Tab'    : 'cycle_all -1',
    m+'-c'         : 'cycle',
    m+'-i'         : 'jumpto urgent'
}

mousebinds = {
  # mouse    
    m+'-Button1'  : 'move',
    m+'-Button2'  : 'zoom',
    m+'-Button3'  : 'resize'
}

# theme

attributes = {
    'theme.tiling.reset'    : '1',
    'theme.floating.reset'  : '1',

    'theme.active.color'    : "'" + color['red500'] + "'",
    'theme.normal.color'    : "'" + color['grey200'] + "'",
    'theme.urgent.color'    : "'" + color['pink500'] + "'",

    'theme.inner_width'     : '0',
    'theme.inner_color'     : 'black',

    'theme.border_width'    : '2',
    'theme.floating.border_width' : '4',
    'theme.floating.outer_width'  : '1',
    'theme.floating.outer_color'  : "'black'",

    'theme.active.inner_color'    : "'#3E4A00'",
    'theme.active.outer_color'    : "'#3E4A00'",
    'theme.background_color'      : "'#141414'"
}

sets = {
    'frame_border_active_color' : "'" + color['grey200'] + "'",
    'frame_bg_active_color'     : "'" + color['yellow900'] + "'",

    'frame_border_normal_color' : "'" + color['grey50'] + "'",
    'frame_bg_normal_color'     : "'" + color['red500'] + "'",

    'frame_border_width'        : '0',
    'always_show_frame'         : '0',
    'frame_bg_transparent'      : '1',
    'frame_transparent_width'   : '2',
    'frame_gap'                 : '20',


    'window_gap'                : '0',
    'frame_padding'             : '0',
    'smart_window_surroundings' : '0',
    'smart_frame_surroundings'  : '1',
    'mouse_recenter_gap'        : '0'
}

# rules

rules = {
  # normally focus new clients
    'focus=on' : '',

  # zero based array
    'class=Firefox'  : 'tag=' + str(tag_names[1]),
    'class=Chromium' : 'tag=' + str(tag_names[1]),
    'class=Geany'    : 'tag=' + str(tag_names[2]),
    'class=Thunar'   : 'tag=' + str(tag_names[3]),
    'class=gimp'     : 'tag=' + str(tag_names[4]) + ' pseudotile=on',

    'class=Oblogout' : 'fullscreen=on',
    
    "class~'(.*[Rr]xvt.*|.*[Tt]erm|Konsole)'" : 'focus=on',

    "windowtype~'_NET_WM_WINDOW_TYPE_(DIALOG|UTILITY|SPLASH)'" : 'pseudotile=on',
  # "windowtype='_NET_WM_WINDOW_TYPE_DIALOG'" : 'focus=on',
    "windowtype='_NET_WM_WINDOW_TYPE_DIALOG'" : 'fullscreen=on ',
    "windowtype~'_NET_WM_WINDOW_TYPE_(NOTIFICATION|DOCK|DESKTOP)'" : 'manage=off'
}

# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# helper

def hc(arguments):
    os.system("herbstclient "+arguments)

def do_config(command, dictionary):
    # loop over dictionary
    for key, value in dictionary.items():
        hc(command+' '+key+' '+value)

        # uncomment to debug in terminal
        # print(command+' '+key+' '+value)

# tags related

def set_tags_with_name():
    hc("rename default '" + str(tag_names[0]) + "' 2>/dev/null || true")
    
    for index, tag_name in enumerate(tag_names):
        hc("add '" + str(tag_names[index]) + "'")
        
        # uncomment to debug in terminal
        # print(index)

        key = tag_keys[index];
        if key:
            hc("keybind Mod4-" + str(key) 
                + " use_index '" + str(index) + "'")
            hc("keybind Mod4-Shift-" + str(key) 
                + " move_index '" + str(index) + "'")

# miscellanous

# I don't understand what this is
def bind_cycle_layout():
    # The following cycles through the available layouts
    # within a frame, but skips layouts, if the layout change 
    # wouldn't affect the actual window positions.
    # I.e. if there are two windows within a frame,
    # the grid layout is skipped.

    hc( "keybind Mod4-space " \
        "or , and . compare tags.focus.curframe_wcount = 2 " \
        ". cycle_layout +1 vertical horizontal max vertical grid " \
        ", cycle_layout +1 ")

# do multi monitor setup here, e.g.:
# hc("set_monitors 1280x1024+0+0 1280x1024+1280+0")
# or simply:
# hc("detect_monitors")

# find the panel

def do_panel():
    dirname = os.path.dirname(os.path.abspath(__file__))
    panel   = dirname + "/panel-lemonbar.py"

    if not os.path.isfile(panel) and os.access(panel, os.X_OK):
        panel = "/etc/xdg/herbstluftwm/panel.sh"
    
    raw = os.popen('herbstclient list_monitors | cut -d: -f1').read()
    monitors = raw.split("\n")

    for monitor in (monitors):
        os.system(panel + ' ' + str(monitor) + ' &');

# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# load on startup

def startup_run():
    command = 'silent new_attr bool my_not_first_autostart'
    exitcode = os.system('herbstclient ' + command)

    if exitcode == 0:
      # non windowed app
        os.system("compton &")
        os.system("dunst &")
        os.system("parcellite &")
        os.system("nitrogen --restore &")
        os.system("mpd &")

      # windowed app
        os.system("xfce4-terminal &")
        os.system("sleep 1 && firefox &")
        os.system("sleep 2 && geany &")
        os.system("sleep 2 && thunar &")


# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# main

# background before wallpaper
os.system("xsetroot -solid '"+color['blue500']+"'")

# Read the manual in $ man herbstluftwm
hc('emit_hook reload')

# gap counter
os.system("echo 35 > /tmp/herbstluftwm-gap");

# do not repaint until unlock
hc("lock");

# standard
# remove all existing keybindings
hc('keyunbind --all')
hc("mouseunbind --all")
hc("unrule -F")

set_tags_with_name()

# do hash config
do_config("keybind",   keybinds)
do_config("keybind",   tagskeybinds)
do_config("mousebind", mousebinds)
do_config("attr",      attributes)
do_config("set",       sets)
do_config("rule",      rules)

# finishing, some extra miles

# I'm not sure what in this is
bind_cycle_layout()

# example of custom layout
layout = "(split horizontal:0.5:0 " \
         "(clients vertical:0) (clients vertical:0))"
hc("load " + str(tag_names[0]) + " '" + layout + "'")

# tag number 5
hc("floating 5 on")

# hc("set tree_style '╾│ ├└╼─┐'")
hc("set tree_style '⊙│ ├╰»─╮'")

# unlock, just to be sure
hc("unlock")

# launch statusbar panel (e.g. dzen2 or lemonbar)
do_panel()

# load on startup
startup_run()

CLICK TO VIEW

x

gmc.py(raw, dl)

  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
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# google material colors
# https://material.io/guidelines/style/color.html

# Associative Array (Dictionary)
color = {
    'white' : '#ffffff', 
    'black' : '#000000',

    'grey50'      : '#fafafa',
    'grey100'     : '#f5f5f5',
    'grey200'     : '#eeeeee',
    'grey300'     : '#e0e0e0',
    'grey400'     : '#bdbdbd',
    'grey500'     : '#9e9e9e',
    'grey600'     : '#757575',
    'grey700'     : '#616161',
    'grey800'     : '#424242',
    'grey900'     : '#212121',

    'red50'       : '#ffebee',
    'red100'      : '#ffcdd2',
    'red200'      : '#ef9a9a',
    'red300'      : '#e57373',
    'red400'      : '#ef5350',
    'red500'      : '#f44336',
    'red600'      : '#e53935',
    'red700'      : '#d32f2f',
    'red800'      : '#c62828',
    'red900'      : '#b71c1c',
    'redA100'     : '#ff8a80',
    'redA200'     : '#ff5252',
    'redA400'     : '#ff1744',
    'redA700'     : '#d50000',

    'pink50'       : '#fce4ec',
    'pink100'      : '#f8bbd0',
    'pink200'      : '#f48fb1',
    'pink300'      : '#f06292',
    'pink400'      : '#ec407a',
    'pink500'      : '#e91e63',
    'pink600'      : '#d81b60',
    'pink700'      : '#c2185b',
    'pink800'      : '#ad1457',
    'pink900'      : '#880e4f',
    'pinkA100'     : '#ff80ab',
    'pinkA200'     : '#ff4081',
    'pinkA400'     : '#f50057',
    'pinkA700'     : '#c51162',

    'blue50'       : '#e3f2fd',
    'blue100'      : '#bbdefb',
    'blue200'      : '#90caf9',
    'blue300'      : '#64b5f6',
    'blue400'      : '#42a5f5',
    'blue500'      : '#2196f3',
    'blue600'      : '#1e88e5',
    'blue700'      : '#1976d2',
    'blue800'      : '#1565c0',
    'blue900'      : '#0d47a1',
    'blueA100'     : '#82b1ff',
    'blueA200'     : '#448aff',
    'blueA400'     : '#2979ff',
    'blueA700'     : '#2962ff',

    'yellow50'       : '#fffde7',
    'yellow100'      : '#fff9c4',
    'yellow200'      : '#fff59d',
    'yellow300'      : '#fff176',
    'yellow400'      : '#ffee58',
    'yellow500'      : '#ffeb3b',
    'yellow600'      : '#fdd835',
    'yellow700'      : '#fbc02d',
    'yellow800'      : '#f9a825',
    'yellow900'      : '#f57f17',
    'yellowA100'     : '#ffff8d',
    'yellowA200'     : '#ffff00',
    'yellowA400'     : '#ffea00',
    'yellowA700'     : '#ffd600',

    'teal50'       : '#e0f2f1',
    'teal100'      : '#b2dfdb',
    'teal200'      : '#80cbc4',
    'teal300'      : '#4db6ac',
    'teal400'      : '#26a69a',
    'teal500'      : '#009688',
    'teal600'      : '#00897b',
    'teal700'      : '#00796b',
    'teal800'      : '#00695c',
    'teal900'      : '#004d40',
    'tealA100'     : '#a7ffeb',
    'tealA200'     : '#64ffda',
    'tealA400'     : '#1de9b6',
    'tealA700'     : '#00bfa5',

    'green50'       : '#e8f5e9',
    'green100'      : '#c8e6c9',
    'green200'      : '#a5d6a7',
    'green300'      : '#81c784',
    'green400'      : '#66bb6a',
    'green500'      : '#4caf50',
    'green600'      : '#43a047',
    'green700'      : '#388e3c',
    'green800'      : '#2e7d32',
    'green900'      : '#1b5e20',
    'greenA100'     : '#b9f6ca',
    'greenA200'     : '#69f0ae',
    'greenA400'     : '#00e676',
    'greenA700'     : '#00c853',

    'orange50'       : '#fff3e0',
    'orange100'      : '#ffe0b2',
    'orange200'      : '#ffcc80',
    'orange300'      : '#ffb74d',
    'orange400'      : '#ffa726',
    'orange500'      : '#ff9800',
    'orange600'      : '#fb8c00',
    'orange700'      : '#f57c00',
    'orange800'      : '#ef6c00',
    'orange900'      : '#e65100',
    'orangeA100'     : '#ffd180',
    'orangeA200'     : '#ffab40',
    'orangeA400'     : '#ff9100',
    'orangeA700'     : '#ff6d00',

    'deepOrange50'       : '#fbe9e7',
    'deepOrange100'      : '#ffccbc',
    'deepOrange200'      : '#ffab91',
    'deepOrange300'      : '#ff8a65',
    'deepOrange400'      : '#ff7043',
    'deepOrange500'      : '#ff5722',
    'deepOrange600'      : '#f4511e',
    'deepOrange700'      : '#e64a19',
    'deepOrange800'      : '#d84315',
    'deepOrange900'      : '#bf360c',
    'deepOrangeA100'     : '#ff9e80',
    'deepOrangeA200'     : '#ff6e40',
    'deepOrangeA400'     : '#ff3d00',
    'deepOrangeA700'     : '#dd2c00'
}
 

x

panel-lemonbar.py(raw, dl)

  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
#!/usr/bin/env python3
# ------------------------------------------------------------------
#
#     Description: unified config for herbstluftwm lemonbar
#     Created by: Epsi Nurwijayadi <epsi.nurwijayadi@gmail.com)
#
#     Source
#     https://github.com/epsi-rns/dotfiles/tree/master/standalone/lemon-hlwm/python
#
#     Blog
#     http://epsi-rns.github.io/desktop/2017/06/11/herbstlustwm-event-idle-overview.html
#     http://epsi-rns.github.io/desktop/2017/06/04/herbstlustwm-tag-status-python.html
#     http://epsi-rns.github.io/desktop/2017/06/14/herbstlustwm-event-idle-python.html
#
# ------------------------------------------------------------------

import os
import sys
import subprocess

import datetime
import time

from gmc import color

# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# helper

# script arguments
def get_monitor(arguments):
    # ternary operator
    monitor = int(arguments[1]) if (len(arguments) > 1) else 0

    return monitor

# geometry calculation

def get_geometry(monitor):
    raw = os.popen('herbstclient monitor_rect '+ str(monitor)).read()

    if not raw: 
        print('Invalid monitor ' + str(monitor))
        exit(1)
    
    geometry = raw.rstrip().split(' ')
    
    return geometry

def get_top_panel_geometry(height, geometry):
    # geometry has the format X Y W H
    return (int(geometry[0]), int(geometry[1]),
            int(geometry[2]), height)

def get_bottom_panel_geometry(height, geometry):
    # geometry has the format X Y W H
    return (int(geometry[0]) + 0, int(geometry[3]) - height, 
            int(geometry[2]) - 0, height )

# lemon Parameters

def get_params_top(monitor, panel_height):  
    # calculate geometry
    geometry = get_geometry(monitor)
    xpos, ypos, width, height = get_top_panel_geometry(
       panel_height, geometry)

    # geometry: -g widthxheight+x+y
    geom_res = str(width)+'x'+str(height)+'+'+str(xpos)+'+'+str(ypos)

    # color, with transparency
    bgcolor = "'#aa000000'"
    fgcolor = "'#ffffff'"
    
    # XFT: require lemonbar_xft_git 
    font_takaop  = "takaopgothic-9"
    font_symbol  = "PowerlineSymbols-11"
    font_awesome = "FontAwesome-9"

    # finally
    parameters  = ' -g '+geom_res+' -u 2 ' \
                + ' -B '+bgcolor+' -F '+fgcolor \
                + ' -f '+font_takaop+' -f '+font_awesome+' -f '+font_symbol

    return parameters

def get_params_bottom(monitor, panel_height):  
    # calculate geometry
    geometry = get_geometry(monitor)
    xpos, ypos, width, height = get_bottom_panel_geometry(
       panel_height, geometry)

    # geometry: -g widthxheight+x+y
    geom_res = str(width)+'x'+str(height)+'+'+str(xpos)+'+'+str(ypos)

    # color, with transparency
    bgcolor = "'#aa000000'"
    fgcolor = "'#ffffff'"
    
    # XFT: require lemonbar_xft_git 
    font_mono    = "monospace-9"
    font_symbol  = "PowerlineSymbols-11"
    font_awesome = "FontAwesome-9"

    # finally
    parameters  = ' -g '+geom_res+' -u 2 ' \
                + ' -B '+bgcolor+' -F '+fgcolor \
                + ' -f '+font_mono+' -f '+font_awesome+' -f '+font_symbol

    return parameters

def get_lemon_parameters(monitor, panel_height):
    return get_params_top(monitor, panel_height)

# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# output

# initialize

# assuming $ herbstclient tag_status
# 	#1	:2	:3	:4	.5	.6	.7	.8	.9

# custom tag names
TAG_SHOWS = ['一 ichi', '二 ni', '三 san', '四 shi', 
    '五 go', '六 roku', '七 shichi', '八 hachi', '九 kyū', '十 jū']

# initialize variable segment
segment_windowtitle = '' # empty string
tags_status         = [] # empty list
segment_datetime    = '' # empty string

# decoration

SEPARATOR = '%{B-}%{F' + color['yellow500'] + '}|%{B-}%{F-}'

# Powerline Symbol
RIGHT_HARD_ARROW = ""
RIGHT_SOFT_ARROW = ""
LEFT_HARD_ARROW  = ""
LEFT_SOFT_ARROW  = ""

# theme
PRE_ICON    = '%{F' + color['yellow500'] + '}'
POST_ICON   = '%{F-}'

# main

def get_statusbar_text(monitor):
    text = ''

    # draw tags
    text += '%{l}'
    for tag_status in tags_status:
        text += output_by_tag(monitor, tag_status)

    # draw date and time
    text += '%{c}'
    text += output_by_datetime()

    # draw window title    
    text += '%{r}'
    text += output_by_title()
    
    return text

# each segments

def output_by_tag(monitor, tag_status):
    tag_index  = tag_status[1:2]
    tag_mark   = tag_status[0:1]
    tag_name   = TAG_SHOWS[int(tag_index) - 1] # zero based

    # ----- pre tag

    if tag_mark == '#':
        text_pre = '%{B' + color['blue500'] + '}' \
                   '%{F' + color['black'] + '}' \
                   '%{U' + color['white'] + '}%{+u}' \
                 + RIGHT_HARD_ARROW \
                 + '%{B' + color['blue500'] + '}' \
                   '%{F' + color['white'] + '}' \
                   '%{U' + color['white'] + '}%{+u}'
    elif tag_mark == '+':
        text_pre = '%{B' + color['yellow500'] + '}' \
                   '%{F' + color['grey400'] + '}'
    elif tag_mark == ':':
        text_pre = '%{B-}%{F' + color['white'] + '}' \
                   '%{U' + color['red500'] + '}%{+u}'
    elif tag_mark == '!':
        text_pre = '%{B' + color['red500'] + '}' \
                   '%{F' + color['white'] + '}' \
                   '%{U' + color['white'] + '}%{+u}'
    else:
        text_pre = '%{B-}%{F' + color['grey600'] + '}%{-u}'

    # ----- tag by number
    
    # clickable tags
    text_name = '%{A:herbstclient focus_monitor "' \
              + str(monitor) + '" && ' + 'herbstclient use "' \
              + tag_index + '":} ' + tag_name + ' %{A} '

    # non clickable tags
    # text_name = ' ' + tag_name + ' '
    
    # ----- post tag

    if tag_mark == '#':
        text_post = '%{B-}' \
                    '%{F' + color['blue500'] + '}' \
                    '%{U' + color['red500'] + '}%{+u}' \
                  + RIGHT_HARD_ARROW
    else: 
        text_post = ''
    
    text_clear = '%{B-}%{F-}%{-u}';
     
    return (text_pre + text_name + text_post + text_clear)

def output_by_title():
    text = segment_windowtitle + ' ' + SEPARATOR + '  '

    return text

def output_by_datetime():
    return segment_datetime

# setting variables, response to event handler

def set_tag_value(monitor):
    global tags_status

    raw = os.popen('herbstclient tag_status ' + str(monitor)).read()
    raw = raw.strip()
    tags_status = raw.split("\t")

def set_windowtitle(windowtitle):
    global segment_windowtitle
    icon = PRE_ICON + '' + POST_ICON

    segment_windowtitle = ' ' + icon + \
        ' %{B-}%{F' + color['grey700'] + '} ' + windowtitle

def set_datetime():
    global segment_datetime
    now = datetime.datetime.now()
    
    date_icon   = PRE_ICON + '' + POST_ICON
    date_format = '{0:%Y-%m-%d}'
    date_str  = date_format.format(now)
    date_text = date_icon + ' %{B-}' \
              + '%{F' + color['grey700'] + '} ' + date_str

    time_icon   = PRE_ICON + '' + POST_ICON    
    time_format = '{0:%H:%M:%S}'
    time_str  = time_format.format(now)
    time_text = time_icon +' %{B-}' \
              + '%{F' + color['blue500'] + '} ' + time_str

    segment_datetime = date_text + '  ' + time_text

# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# pipe handler

def handle_command_event(monitor, event):
    # find out event origin
    column = event.split("\t")
    origin = column[0]
    
    tag_cmds = ['tag_changed', 'tag_flags', 'tag_added', 'tag_removed']
    title_cmds = ['window_title_changed', 'focus_changed']

    if origin == 'reload':
        os.system('pkill lemonbar')
    elif origin == 'quit_panel':
        exit()
    elif origin in tag_cmds:
        set_tag_value(monitor)
    elif origin in title_cmds:
        title = column[2] if (len(column) > 2) else ''
        set_windowtitle(title)
    elif origin == 'interval':
        set_datetime()

def content_init(monitor, pipe_lemon_out):
    # initialize statusbar before loop
    set_tag_value(monitor)
    set_windowtitle('')
    set_datetime()
        
    text = get_statusbar_text(monitor)
    pipe_lemon_out.stdin.write(text + '\n')
    pipe_lemon_out.stdin.flush()
    
def content_event_idle(pipe_cat_out):
    pid_idle = os.fork()
        
    if pid_idle == 0:
        try:
            # start a pipe
            command_in = 'herbstclient --idle'  
            pipe_idle_in = subprocess.Popen(
                    [command_in], 
                    stdout = subprocess.PIPE,
                    stderr = subprocess.STDOUT,
                    shell  = True,
                    universal_newlines = True
            )
            
            # wait for each event  
            for event in pipe_idle_in.stdout: 
                pipe_cat_out.stdin.write(event)
                pipe_cat_out.stdin.flush()
    
            pipe_idle_in.stdout.close()
        finally:
            import signal
            os.kill(pid_idle, signal.SIGTERM)


def content_event_interval(pipe_cat_out):
    pid_interval = os.fork()

    if pid_interval == 0:
        try:
            while True:
                pipe_cat_out.stdin.write("interval\n")
                pipe_cat_out.stdin.flush()
    
                time.sleep(1)
        finally:
            import signal
            os.kill(pid_interval, signal.SIGTERM)

def content_walk(monitor, pipe_lemon_out): 
    pipe_cat = subprocess.Popen(
            ['cat'], 
            stdin  = subprocess.PIPE,
            stdout = subprocess.PIPE,
            shell  = True,
            universal_newlines=True
        )

    content_event_idle(pipe_cat)
    content_event_interval(pipe_cat)

    # wait for each event, trim newline
    for event in pipe_cat.stdout:
        handle_command_event(monitor, event.strip())

        text = get_statusbar_text(monitor)
        pipe_lemon_out.stdin.write(text + '\n')
        pipe_lemon_out.stdin.flush()

    pipe_cat.stdin.close()
    pipe_cat.stdout.close()

def run_lemon(monitor, parameters):  
    command_out  = 'lemonbar ' + parameters

    pipe_lemon_out = subprocess.Popen(
            [command_out], 
            stdout = subprocess.PIPE, # for use with shell, note this
            stdin  = subprocess.PIPE, # for use with content processing
            shell  = True,
            universal_newlines=True
        )
    
    pipe_sh = subprocess.Popen(
            ['sh'], 
            stdin  = pipe_lemon_out.stdout,
            shell  = True,
            universal_newlines=True
        )

    content_init(monitor, pipe_lemon_out)
    content_walk(monitor, pipe_lemon_out) # loop for each event

    pipe_lemon_out.stdin.close()
    pipe_lemon_out.stdout.close()

def detach_lemon_debug(monitor, parameters):
    run_lemon(monitor, parameters)

def detach_lemon(monitor, parameters):
    # in case of debugging purpose, 
    # uncomment all the fork related lines.
    pid_lemon = os.fork()
    
    if pid_lemon == 0:
        try:
            run_lemon(monitor, parameters)
            os._exit(1)
        finally:
            import signal
            os.kill(pid_lemon, signal.SIGTERM)

def detach_lemon_conky(parameters):
    pid_conky = os.fork()
    
    if pid_conky == 0:
        try:
            dirname  = os.path.dirname(os.path.abspath(__file__))
            cmd_in   = 'conky -c ' + dirname + '/conky-lemonbar.lua'

            cmd_out  = 'lemonbar ' + parameters

            pipe_out = subprocess.Popen(
                    [cmd_out], 
                    stdin  = subprocess.PIPE,
                    shell  = True,
                    universal_newlines=True
                )

            pipe_in  = subprocess.Popen(
                    [cmd_in], 
                    stdout = pipe_out.stdin,
                    stderr = subprocess.STDOUT,
                    shell  = True,
                    universal_newlines = True
                )

            pipe_out.stdin.close()
            outputs, errors = pipe_out.communicate()
    
            # avoid zombie apocalypse
            pipe_out.wait()

            os._exit(1)
        finally:
            import signal
            os.kill(pid_conky, signal.SIGTERM)

def kill_zombie():
    os.system('pkill -x dzen2')
    os.system('pkill -x lemonbar')
    os.system('pkill -x cat')
    os.system('pkill conky')
    os.system('pkill herbstclient')

# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# main

panel_height = 24
monitor = get_monitor(sys.argv)

kill_zombie()
os.system('herbstclient pad ' + str(monitor) + ' ' 
    + str(panel_height) + ' 0 ' + str(panel_height) + ' 0')

# run process in the background

params_top    = get_params_top(monitor, panel_height)
detach_lemon(monitor, params_top)

params_bottom = get_params_bottom(monitor, panel_height)
detach_lemon_conky(params_bottom)
 

x

gmc.lua(raw, dl)

  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
-- vim: ts=4 sw=4 noet ai cindent syntax=lua

-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- google material colors
-- https://material.io/guidelines/style/color.html
  
colWhite = '\\#ffffff'
colBlack = '\\#000000'

colGrey50  = '\\#fafafa'
colGrey100 = '\\#f5f5f5'
colGrey200 = '\\#eeeeee'
colGrey300 = '\\#e0e0e0'
colGrey400 = '\\#bdbdbd'
colGrey500 = '\\#9e9e9e'
colGrey600 = '\\#757575'
colGrey700 = '\\#616161'
colGrey800 = '\\#424242'
colGrey900 = '\\#212121'

colRed50   = '\\#ffebee'
colRed100  = '\\#ffcdd2'
colRed200  = '\\#ef9a9a'
colRed300  = '\\#e57373'
colRed400  = '\\#ef5350'
colRed500  = '\\#f44336'
colRed600  = '\\#e53935'
colRed700  = '\\#d32f2f'
colRed800  = '\\#c62828'
colRed900  = '\\#b71c1c'
colRedA100 = '\\#ff8a80'
colRedA200 = '\\#ff5252'
colRedA400 = '\\#ff1744'
colRedA700 = '\\#d50000'

colPink50   = '\\#fce4ec'
colPink100  = '\\#f8bbd0'
colPink200  = '\\#f48fb1'
colPink300  = '\\#f06292'
colPink400  = '\\#ec407a'
colPink500  = '\\#e91e63'
colPink600  = '\\#d81b60'
colPink700  = '\\#c2185b'
colPink800  = '\\#ad1457'
colPink900  = '\\#880e4f'
colPinkA100 = '\\#ff80ab'
colPinkA200 = '\\#ff4081'
colPinkA400 = '\\#f50057'
colPinkA700 = '\\#c51162'

colIndigo50   = '\\#e8eaf6'
colIndigo100  = '\\#c5cae9'
colIndigo200  = '\\#9fa8da'
colIndigo300  = '\\#7986cb'
colIndigo400  = '\\#5c6bc0'
colIndigo500  = '\\#3f51b5'
colIndigo600  = '\\#3949ab'
colIndigo700  = '\\#303f9f'
colIndigo800  = '\\#283593'
colIndigo900  = '\\#1a237e'
colIndigoA100 = '\\#8c9eff'
colIndigoA200 = '\\#536dfe'
colIndigoA400 = '\\#3d5afe'
colIndigoA700 = '\\#304ffe'

colBlue50   = '\\#e3f2fd'
colBlue100  = '\\#bbdefb'
colBlue200  = '\\#90caf9'
colBlue300  = '\\#64b5f6'
colBlue400  = '\\#42a5f5'
colBlue500  = '\\#2196f3'
colBlue600  = '\\#1e88e5'
colBlue700  = '\\#1976d2'
colBlue800  = '\\#1565c0'
colBlue900  = '\\#0d47a1'
colBlueA100 = '\\#82b1ff'
colBlueA200 = '\\#448aff'
colBlueA400 = '\\#2979ff'
colBlueA700 = '\\#2962ff'

colYellow50   = '\\#fffde7'
colYellow100  = '\\#fff9c4'
colYellow200  = '\\#fff59d'
colYellow300  = '\\#fff176'
colYellow400  = '\\#ffee58'
colYellow500  = '\\#ffeb3b'
colYellow600  = '\\#fdd835'
colYellow700  = '\\#fbc02d'
colYellow800  = '\\#f9a825'
colYellow900  = '\\#f57f17'
colYellowA100 = '\\#ffff8d'
colYellowA200 = '\\#ffff00'
colYellowA400 = '\\#ffea00'
colYellowA700 = '\\#ffd600'

colTeal50   = '\\#e0f2f1'
colTeal100  = '\\#b2dfdb'
colTeal200  = '\\#80cbc4'
colTeal300  = '\\#4db6ac'
colTeal400  = '\\#26a69a'
colTeal500  = '\\#009688'
colTeal600  = '\\#00897b'
colTeal700  = '\\#00796b'
colTeal800  = '\\#00695c'
colTeal900  = '\\#004d40'
colTealA100 = '\\#a7ffeb'
colTealA200 = '\\#64ffda'
colTealA400 = '\\#1de9b6'
colTealA700 = '\\#00bfa5'

colGreen50   = '\\#e8f5e9'
colGreen100  = '\\#c8e6c9'
colGreen200  = '\\#a5d6a7'
colGreen300  = '\\#81c784'
colGreen400  = '\\#66bb6a'
colGreen500  = '\\#4caf50'
colGreen600  = '\\#43a047'
colGreen700  = '\\#388e3c'
colGreen800  = '\\#2e7d32'
colGreen900  = '\\#1b5e20'
colGreenA100 = '\\#b9f6ca'
colGreenA200 = '\\#69f0ae'
colGreenA400 = '\\#00e676'
colGreenA700 = '\\#00c853'

colOrange50   = '\\#fff3e0'
colOrange100  = '\\#ffe0b2'
colOrange200  = '\\#ffcc80'
colOrange300  = '\\#ffb74d'
colOrange400  = '\\#ffa726'
colOrange500  = '\\#ff9800'
colOrange600  = '\\#fb8c00'
colOrange700  = '\\#f57c00'
colOrange800  = '\\#ef6c00'
colOrange900  = '\\#e65100'
colOrangeA100 = '\\#ffd180'
colOrangeA200 = '\\#ffab40'
colOrangeA400 = '\\#ff9100'
colOrangeA700 = '\\#ff6d00'

colDeepOrange50   = '\\#fbe9e7'
colDeepOrange100  = '\\#ffccbc'
colDeepOrange200  = '\\#ffab91'
colDeepOrange300  = '\\#ff8a65'
colDeepOrange400  = '\\#ff7043'
colDeepOrange500  = '\\#ff5722'
colDeepOrange600  = '\\#f4511e'
colDeepOrange700  = '\\#e64a19'
colDeepOrange800  = '\\#d84315'
colDeepOrange900  = '\\#bf360c'
colDeepOrangeA100 = '\\#ff9e80'
colDeepOrangeA200 = '\\#ff6e40'
colDeepOrangeA400 = '\\#ff3d00'
colDeepOrangeA700 = '\\#dd2c00'
 

x

conky-lemonbar.lua(raw, dl)

  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
-- vim: ts=4 sw=4 noet ai cindent syntax=lua

-- ------------------------------------------------------------------
--
--     Description: unified config for standalone conky lemonbar
--     Created by: Epsi Nurwijayadi <epsi.nurwijayadi@gmail.com)
--
--     Source
--     https://github.com/epsi-rns/dotfiles/tree/master/standalone/lemon/conky
--
--     Blog
--     http://epsi-rns.github.io/desktop/2017/04/14/standalone-lemonbar-conky.html
--
-- ------------------------------------------------------------------

--[[
Conky, a system monitor, based on torsmo
]]

conky.config = {
    out_to_x = false,
    out_to_console = true,
    short_units = true,
    update_interval = 1
}

--[[
Prepare
]]

local dirname  = debug.getinfo(1).source:match("@?(.*/)")
dofile(dirname .. 'gmc.lua')

-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- helper

helper = {}

-- constant

helper.alphaValue = 'aa'

colorPresetDark = {
  icon       = colYellow500,
  label      = colBlue500,  
  value      = colGrey700,
  underline  = colWhite,
  background = '-'
}

colorPresetBright = {
  icon       = colWhite,
  label      = colPink500,  
  value      = colWhite,
  underline  = colBlack,
  background = '-'
}

helper.count = 0
colorPreset = colorPresetDark

-- lemonade

function helper.alpha(color)
  alphaValue = helper.alphaValue

  color = string.sub(color, 3)
  color = '\\#' .. alphaValue .. color
  
  return color
end

function helper.lemonized(tag, color)
  return '%{' .. tag .. color .. '}'
end

function helper.lemonForeground(color)
  return '%{F' .. color .. '}'
end

function helper.lemonBackground(color)
  return '-' and '%{B-}' or '%{B' .. color .. '}'
end

function helper.lemonBackgroundAlpha(color)
  return '-' and '%{B-}' or '%{B' .. helper.alpha(color) .. '}'
end

function helper.lemonUnderline(color)
  return '%{U' .. color .. '}'
end

function helper.lemonReset()
  return '%{B-}%{F-}%{-u}'
end

-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---

function helper.icon(text, color)
  color = color or colorPreset.icon  
  return ' ' .. helper.lemonForeground(color) .. text .. ' '
end

function helper.label(text, color)
  color = color or colorPreset.label
  return helper.lemonForeground(color) .. text
end

function helper.separator(color)
  color = color or colorPreset.separator
  return helper.lemonForeground(color) .. '|'
end

function helper.value(text, color)
  color = color or colorPreset.value
  return helper.lemonForeground(color) .. text
end

-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---

function helper.common(icon, label, value)
  text = ''
  
  if icon  then text = text 
    .. helper.icon(icon, colorPreset.icon)                
  end  
    
  if label then text = text 
    .. ' ' .. helper.label(label, colorPreset.label)        
  end  
    
  if value then text = text 
    .. ' ' .. helper.value(value, colorPreset.value) .. ' ' 
  end
  
  return text
end

function helper.compose(icon, label, value, colorBg)
  colorBg = colorBg or colorPreset.background   

  if (helper.count % 2) == 0 then
    colorPreset = colorPresetDark
  else
    colorPreset = colorPresetBright
  end
  
  text = helper.lemonBackgroundAlpha(colorBg)
  text = text .. helper.lemonUnderline(colorPreset.underline)   
  text = text .. helper.common(icon, label, value)
  text ='%{+u}' ..  text .. '%{-u}' .. helper.lemonReset()
  
  helper.count = helper.count + 1
  
  return text
end

-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- parts

--[[
You may consider change glyph using FontAwesome icon
http://fontawesome.io/cheatsheet/

* Sample: Battery Icon: 
]]

parts = {}

-- user variables
local wlandev = 'wlp0s3f3u2'

-- shortcut
local _h = helper

-- template variables: Color Indicator
local color_indicator_dark = {
  good      = colBlack,
  degraded  = colRed900,
  bad       = colRed500
}

local color_indicator_bright = {
  good      = colGrey300,
  degraded  = colRed700,
  bad       = colRed900
}

local ci = color_indicator_bright

-- Separator

function parts.separator(colorBgSt, colorBgNd, colorFg)
  text = '%{+u}'
  text = text .. _h.lemonForeground(colorFg)
  text = text .. _h.lemonBackgroundAlpha(colorBgSt)

  if (helper.count % 2) == 0 then
    colorUnderline = colBlack
  else
    colorUnderline = colWhite
  end
  
  text = text .. _h.lemonUnderline(colorUnderline)  
  text = text .. ''
  
  text = text .. _h.lemonBackgroundAlpha(colorBgNd)

  if (helper.count % 2) == 0 then
    colorUnderline = colWhite
  else
    colorUnderline = colBlack
  end
  
  text = text .. _h.lemonUnderline(colorUnderline)   
  text = text .. ''
  text = text .. '%{-u}'
    
  return text
end

-- Time
function parts.time(colorBg)

  return _h.compose('', nil, '${time %H:%M }', colorBg)
end

-- Date
function parts.date(colorBg)

  return _h.compose('', nil, '${time %D}', colorBg)
end

-- Volume
function parts.volume(colorBg)

  local volume_command = [[amixer get Master | tail -1 | sed 's/.*\[\([0-9]*%\)\].*/\1/']]
  return _h.compose('', 'Vol', "${execi 1 " .. volume_command .. "}", colorBg)
end

-- Host
function parts.host(colorBg)

  return _h.compose('', 'Host', '$nodename', colorBg)
end

-- Uptime
function parts.uptime(colorBg)

  return _h.compose('', 'Uptime', '$uptime', colorBg)
end

-- Memory
function parts.mem(colorBg)

  return _h.compose('', 'RAM', '$mem/$memmax', colorBg)
end

-- SSID
function parts.ssid(colorBg)

  return _h.compose(' ', '', '$wireless_essid', colorBg)
end


-- Lua Function Demo 
-- https://github.com/brndnmtthws/conky/issues/62

function _h.exec(command)
    local file = assert(io.popen(command, 'r'))
    local s = file:read('*all')
    file:close()

    s = string.gsub(s, '^%s+', '') 
    s = string.gsub(s, '%s+$', '') 
    s = string.gsub(s, '[\n\r]+', ' ')

    return s
end

-- read once
local machine = _h.exec('uname -r')  

function parts.machine(colorBg)

  return _h.compose('', nil, machine, colorBg)
end

-- Media Player Daemon
function parts.mpd(colorBg)

  local mpd = [[\
${if_mpd_playing}\
]] .. _h.icon('') 
.. _h.value(' ${mpd_artist 20} ')
.. _h.icon('')
.. _h.value(' ${mpd_title 30}') ..[[
${else}]] .. _h.icon('') .. [[${endif}\
]]

  return _h.compose(nil, nil, mpd, colorBg)
end

-- CPU temperature:
function parts.cputemp(colorBg)
  local cputemp = [[\
${if_match ${acpitemp}<45}\
]] .. _h.value('${acpitemp}°C', ci.good) .. [[
${else}${if_match ${acpitemp}<55}\
]] .. _h.value('${acpitemp}°C', ci.degraded) .. [[
${else}${if_match ${acpitemp}>=55}\
]] .. _h.value('${acpitemp}°C', ci.bad) .. [[
${endif}${endif}${endif}\
]]

  return _h.compose('', 'CPU', cputemp, colorBg)
end

-- Network
function parts.network(colorBg)

  local download = _h.icon('') .. [[\
${if_match ${downspeedf ]] .. wlandev .. [[}<1000}\
]] .. _h.value('${downspeed ' .. wlandev .. '}', ci.good) .. [[
${else}${if_match ${downspeedf ]] .. wlandev .. [[}<3000}\
]] .. _h.value('${downspeed ' .. wlandev .. '}', ci.degraded) .. [[
${else}${if_match ${downspeedf ]] .. wlandev .. [[}>=3000}\
]] .. _h.value('${downspeed ' .. wlandev .. '}', ci.bad) .. [[
${endif}${endif}${endif}\
]]

  local upload = _h.icon('') .. [[\
${if_match ${upspeedf ]] .. wlandev .. [[}<300}\
]] .. _h.value('${upspeed ' .. wlandev .. '}', ci.good) .. [[
${else}${if_match ${upspeedf ]] .. wlandev .. [[}<800}\
]] .. _h.value('${upspeed ' .. wlandev .. '}', ci.degraded) .. [[
${else}${if_match ${upspeedf ]] .. wlandev .. [[}>=800}\
]] .. _h.value('${upspeed ' .. wlandev .. '}', ci.bad) .. [[
${endif}${endif}${endif}\
]]

  return _h.compose(nil, nil, download .. upload, colorBg)
end

-- Memory
function parts.memory(colorBg)

  local memory = [[\
${if_match ${memperc}<30}\
]] .. _h.value('${memeasyfree}', ci.good) .. [[
${else}${if_match ${memperc}<70}\
]] .. _h.value('${memeasyfree}',ci.degraded) .. [[
${else}${if_match ${memperc}>=70}\
]] .. _h.value('${memeasyfree}', ci.bad) .. [[
${endif}${endif}${endif}\
]]

  return _h.compose('', 'MEM', memory, colorBg)
end

-- CPU 0
function parts.cpu0(colorBg)

 local cpu0 = [[\
${if_match ${cpu cpu0}<50}\
]] .. _h.value('${cpu cpu0}%', ci.good) .. [[
${else}${if_match ${cpu cpu0}<60}\
]] .. _h.value('${cpu cpu0}%',ci.degraded) .. [[
${else}${if_match ${cpu cpu0}<=100}\
]] .. _h.value('${cpu cpu0}%', ci.bad) .. [[
${endif}${endif}${endif}\
]]

  return _h.compose('', 'CPU', cpu0, colorBg)
end

-- Battery
function parts.battery(colorBg)

  local battery = [[\
${if_match ${battery_percent}<30}\
]] .. _h.value('${battery_percent}%', ci.bad) .. [[
${else}${if_match ${battery_percent}<70}\
]] .. _h.value('${battery_percent}%', ci.degraded) .. [[
${else}${if_match ${battery_percent}>=70}\
]] .. _h.value('${battery_percent}%', ci.good) .. [[
${endif}${endif}${endif}\
]]

  return _h.compose('', 'Battery', battery, colorBg)
end

-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- assembly

--[[
disabled = ''
-- .. parts.host      (colBlue400)
-- .. parts.volume    (colBlue300)
-- .. parts.separator (colBlue300, colGreen400, colBlue500)
-- .. parts.battery   (colBlue400)   
-- .. parts.mem       (colBlue400)
-- .. parts.ssid      (colBlue400)
-- .. parts.network   (colBlue400)
-- .. parts.mpd       (colBlue400)
-- .. parts.date      (colBlue400)
-- .. parts.time      (colBlue400)
-- .. parts.machine   (colBlue400)

enabled = ''

   .. parts.uptime    (colGreen400)
   .. parts.separator (colGreen400, colBlue500, colGreen200)
   .. parts.cpu0      (colBlue500)
   .. parts.separator (colBlue500, colGreen500, colBlue300)
   .. parts.cputemp   (colGreen500)
   .. parts.separator (colGreen500, colBlue400, colGreen300)
   .. parts.memory    (colBlue400)
]]

-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- main

-- shortcut
local _h = helper
lf = helper.lemonForeground
lb = helper.lemonBackground
la = helper.lemonBackgroundAlpha
lu = helper.lemonUnderline
lr = helper.lemonReset

conky.text = [[\
%{l}\
]] .. lr() .. lf(colRed500) .. [[  \
]] .. parts.uptime    () .. [[\
%{c}\
]] .. lr() .. [[\
]] -- .. enabled
   .. parts.battery   () 
   .. parts.cpu0      ()
   .. parts.cputemp   ()
   .. parts.memory    ()
   .. parts.volume    ()
   .. lr() .. [[\
%{r}\
]] .. lr() .. [[\
]] .. parts.host      () .. [[\
]] .. lf(colRed500) .. [[  \
]]
 

x

Notes

[Part Two] HerbstluftWM Idle Event

This is a complementary topic for previous “Modularized HerbstluftWM Configuration” article. I have done, implementing herbstluftwm idle event. Both Dzen2 and Lemonbar, designed specifically for HerbstluftWM’s Tag. This [part two], contain Advance Pipe and Fork, a very interesting topic.

“Once hard, now easy.”

»»

Blog

Overview
¤ http://epsi-rns.github.io/desktop/2017/06/11/herbstlustwm-event-idle-overview.html

BASH
¤ http://epsi-rns.github.io/desktop/2017/06/12/herbstlustwm-event-idle-bash.html

Perl
¤ http://epsi-rns.github.io/desktop/2017/06/13/herbstlustwm-event-idle-perl.html

Python
¤ http://epsi-rns.github.io/desktop/2017/06/14/herbstlustwm-event-idle-python.html

Ruby
¤ http://epsi-rns.github.io/desktop/2017/06/15/herbstlustwm-event-idle-ruby.html

PHP
¤ http://epsi-rns.github.io/desktop/2017/06/16/herbstlustwm-event-idle-php.html

Lua
¤ http://epsi-rns.github.io/desktop/2017/06/07/herbstlustwm-tag-status-lua.html

Haskell
¤ http://epsi-rns.github.io/desktop/2017/06/18/herbstlustwm-event-idle-haskell.html

»»

Source Code

Dzen2
¤ https://github.com/epsi-rns/dotfiles/tree/master/standalone/dzen2-hlwm

Lemonbar
¤ https://github.com/epsi-rns/dotfiles/tree/master/standalone/lemon-hlwm

standalone #modular #herbstluftwm #lemonbar #dzen2 #pipe #fork

bash #perl #python #ruby #php #lua #haskell

»»

Finally Finished

I hope that, this material useful.

Thank you for reading.