guest@dotshare [~/groups/info/conky] $ ls Standalone-CLI-Conky/ | cat

Standalone CLI Conky (scrot)

epsi Jul 06, 2017 (info/conky)

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

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

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

-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- Initialize ANSI

ansiEscape    = ""

-- Foreground ansiors
ansiFgBlack   = ansiEscape .. "[30m" 
ansiFgRed     = ansiEscape .. "[31m"   
ansiFgGreen   = ansiEscape .. "[32m"
ansiFgYellow  = ansiEscape .. "[33m" 
ansiFgBlue    = ansiEscape .. "[34m"  
ansiFgPurple  = ansiEscape .. "[35m"
ansiFgCyan    = ansiEscape .. "[36m"   
ansiFgWhite   = ansiEscape .. "[37m"

-- Background ansiors
ansiBgBlack   = ansiEscape .. "[40m"  
ansiBgRed     = ansiEscape .. "[41m"   
ansiBgGreen   = ansiEscape .. "[42m"
ansiBgYellow  = ansiEscape .. "[43m" 
ansiBgBlue    = ansiEscape .. "[44m"  
ansiBgPurple  = ansiEscape .. "[45m"
ansiBgCyan    = ansiEscape .. "[46m"   
ansiBgWhite   = ansiEscape .. "[47m"

-- Special Character Conditions
ansiBoldOn       = ansiEscape .. "[1m"   
ansiBoldOff      = ansiEscape .. "[22m"
ansiItalicsOn    = ansiEscape .. "[3m"
ansiItalicsOff   = ansiEscape .. "[23m"
ansiUnderlineOn  = ansiEscape .. "[4m"
ansiUnderlineOff = ansiEscape .. "[24m"
ansiInvertOn     = ansiEscape .. "[7m"    
ansiInvertOff    = ansiEscape .. "[27m"

-- Reset to default configuration
ansiReset     = ansiEscape .. "[0m"

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

helper = {}

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

function helper.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


function helper.gototopleft()
  return helper.exec('tput cup 0 0') 
--  return ''
end

function helper.newline()
  return helper.exec('echo "\n\n\n\n"') 
end

-- template variables
local ansiPresetDark = {
  icon      = ansiFgRed,
  label     = ansiFgBlack .. ansiBoldOn,
  value     = ansiFgBlue .. ansiBoldOff
}

local ansiPresetBright = {
  icon      = ansiFgRed,
  label     = ansiFgBlack .. ansiBoldOn,
  value     = ansiFgBlack .. ansiBoldOff
}

local ansiPreset = ansiPresetBright

-- ----- 

function helper.icon(text, ansi)
  ansi = ansi or ansiPreset.icon
 
  return ansi .. ' ' .. text .. ' '
end

function helper.label(text, ansi)
  ansi = ansi or ansiPreset.label

  return ansi .. text
end

function helper.value(text, ansi)
  ansi = ansi or ansiPreset.value

  return ansi .. text 
end

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

  return text
end

-- miscellanous

function helper.progressbar(value)
  -- Predefined
  maximum=100
  width=25
  symbol="=" 

  -- number of block
  count = (value * width) // maximum
    
  -- Create the progress bar string.
  row=''
  for i=1,count do row = row .. symbol end
  for i=count,width do row = row .. ' ' end

  return ' [' .. row .. '] '
end

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

parts = {}

-- user variables
local wlandev = 'wlp0s3f3u2'

-- shortcut
local _h = helper

-- constant
parts.arrow = ansiBoldOff .. ''

-- template variables: Color Indicator
local color_indicator_dark = {
  good      = ansiFgBlack,
  degraded  = ansiFgPurple,
  bad       = ansiFgRed 
}

local color_indicator_bright = {
  good      = ansiFgBlack,
  degraded  = ansiFgPurple,
  bad       = ansiFgRed 
}

local ci = color_indicator_bright

-- transition image
function parts.transition(decoIcon, decoBg, decoFg)
   text = '^bg(' .. decoBg .. ')' 
       .. '^fg(' .. decoFg .. ')' .. decoIcon

  return text
end

-- Newline
parts.newline = [[
  
]]

-- Time
parts.time = _h.common('', nil, '${time %H:%M }')

-- Date
parts.date = _h.common('', nil, '${time %D}')

-- Date Time (time for dating)
parts.datetime =  ansiBgWhite .. ansiFgRed .. '  '
  .. ansiBgRed .. ansiFgWhite .. parts.arrow
  .. ansiBoldOn .. ' ${time %D} '
  .. ansiBgWhite .. ansiFgRed .. parts.arrow
  .. ' ${time %H:%M } '
  .. ansiReset .. ansiFgWhite .. parts.arrow
  .. ansiReset
  
-- Title
parts.title = ansiBgWhite .. ansiFgBlue .. parts.arrow
  .. ' Command Line Interface '
  .. ansiBgBlue .. ansiFgWhite .. parts.arrow
  .. ansiBoldOn .. ' System Monitoring '
  .. ansiReset .. ansiFgBlue .. parts.arrow
  .. ansiReset

-- Volume
local volume_command = [[amixer get Master | tail -1 | sed 's/.*\[\([0-9]*%\)\].*/\1/']]

parts.volume = _h.common('', 'Volume  ', "${execi 1 " .. volume_command .. "}")

-- Host
parts.host = _h.common('', 'Host    ',
  ansiUnderlineOn .. '$nodename' .. ansiUnderlineOff) 

-- Uptime
parts.uptime = _h.common('', 'Uptime  ', '$uptime')

-- Memory
parts.mem = _h.common('', 'RAM     ', '$mem/$memmax')

-- SSID
parts.ssid = _h.common('', 'ESSID   ', '$wireless_essid')

-- 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')
machine = ansiItalicsOn .. machine .. ansiItalicsOff  

parts.machine = _h.common('', nil, machine)

-- Media Player Daemon
parts.mpd = [[\
${if_mpd_playing}\
]] .. ' ' .. _h.icon('') 
.. _h.value(' ${mpd_artist 20} ')
.. _h.icon('')
.. _h.value(' ${mpd_title 30}') 
.. '                     ' .. [[
${else}]] .. ' '.. _h.icon('') .. ' '
.. _h.label('Pause     ')
.. '                     ' .. [[${endif}\
]]

-- CPU temperature:
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}\
]]

parts.cputemp = _h.common('', 'CPU Temp', cputemp)


-- Network
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}\
]]

parts.network = _h.common(' ', nil, download .. upload .. '          ')

-- Memory
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}\
]]

parts.memory = _h.common('', 'Memory  ', memory)


-- CPU 0
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}\
]]

parts.cpu0 = _h.common('', 'CPU Load', cpu0)

-- Battery
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}\
]]

parts.battery = _h.common('', 'Battery ', battery)

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

-- shortcut
local _h = helper

--[[
-- if you care about performance, comment-out this variable.
disabled = ''
    .. parts.title     
    .. parts.newline    
    .. parts.newline
    .. parts.date
    .. parts.time    
    .. parts.newline 
    .. parts.mem    
]]

enabled = ''
    .. parts.newline 
    .. parts.newline

    .. parts.uptime
    .. parts.newline
    .. parts.host
    .. parts.machine    
    .. parts.newline
    
    .. parts.volume
    .. parts.newline
    .. parts.mpd
    .. parts.newline
    .. parts.newline 
       
    .. parts.datetime   
    .. parts.newline 
    .. parts.newline

    .. parts.cpu0        
    .. parts.newline
    .. parts.cputemp
    .. parts.newline
    .. parts.memory
    .. parts.newline
    .. parts.battery    
      
    .. parts.newline
    .. parts.newline
    .. parts.ssid
    .. parts.network
    .. parts.newline 
    .. parts.newline
    
conky.text = _h.gototopleft() .. [[\
]] .. enabled .. [[
]]

CLICK TO VIEW

x

main.sh(raw, dl)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#!/usr/bin/env bash

# hide cursor
tput civis  -- invisible
# type' tput cnorm' to show

clear

DIR=$(dirname "$0")
conky -c ${DIR}/conky.lua 
 

x