jsonparts.lua 4.38 KB
Newer Older
epsi sayidina's avatar
i3wm  
epsi sayidina committed
1 2 3 4 5 6 7 8 9 10 11 12 13
-- vim: ts=4 sw=4 noet ai cindent syntax=lua

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

* Sample: Battery Icon: 
]]


parts = {}

-- user variables
epsi sayidina's avatar
epsi sayidina committed
14
local wlandev = 'wlp0s3f3u2'
epsi sayidina's avatar
i3wm  
epsi sayidina committed
15 16 17 18 19

-- shortcut
local _h = jsonhelper

-- template variables: Color Indicator
epsi sayidina's avatar
epsi sayidina committed
20
local color_indicator_dark = {
epsi sayidina's avatar
i3wm  
epsi sayidina committed
21
  good      = '#909737',
epsi sayidina's avatar
epsi sayidina committed
22 23
  degraded  = '#b27d12',
  bad       = '#802828'
epsi sayidina's avatar
i3wm  
epsi sayidina committed
24 25
}

epsi sayidina's avatar
epsi sayidina committed
26 27 28 29 30 31 32 33
local color_indicator_bright = {
  good      = '#202080',
  degraded  = '#802080',
  bad       = '#802020'
}

local ci = color_indicator_bright

epsi sayidina's avatar
i3wm  
epsi sayidina committed
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
-- Time
parts.time = _h.common('', nil, '${time %H:%M }')

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

-- Volume
local volume_command = [[amixer sget Master,0 | egrep -o '([0-9]+%|\[(on|off)\])' | sed ':a;N;$!ba;s/\n/ /g']]
parts.volume = _h.common('', 'VOL', "${execi 1 " .. volume_command .. "}")

-- Host
parts.host = _h.common('', 'Host', '$nodename') 

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

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

-- 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')  
parts.machine = _h.common('', nil, machine)

-- Media Player Daemon
parts.mpd = [[
${if_mpd_playing} 
]] .. _h.icon('') .. [[,
epsi sayidina's avatar
epsi sayidina committed
76
    {"full_text":"${mpd_artist 20}", "color" : "\#545454", 
epsi sayidina's avatar
i3wm  
epsi sayidina committed
77 78 79
     "separator" : false, "separator_block_width":3 },
    {"full_text":" - ", "color" : "\#909737", 
     "separator" : false, "separator_block_width":3 },
epsi sayidina's avatar
epsi sayidina committed
80
    {"full_text":"${mpd_title 30}", "color" : "\#5c5dad", 
epsi sayidina's avatar
i3wm  
epsi sayidina committed
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
     "separator" : false, "separator_block_width":6 }
${else} 
    {"full_text":"", "color":"\#c92525", 
     "separator" : false, "separator_block_width":6 }
${endif} 
]]

-- CPU temperature:
parts.cputemp = _h.common('', 'CPU') .. [[,
${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}
]]

-- Download
parts.download = _h.common(' ', 'DOWN') .. [[,
${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}
]]

-- Upload
parts.upload = _h.common('', 'UP') .. [[,
${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}
]]

-- Memory
parts.memory = _h.common('', 'MEM') .. [[,
${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}
]]

-- CPU 0
parts.cpu0 = _h.common('', 'CPU') .. [[,
${if_match ${cpu cpu0}<50}
    ]] .. _h.value('${cpu cpu0}%', ci.good) .. [[
${else}${if_match ${cpu cpu0}<60E}
    ]] .. _h.value('${cpu cpu0}%',ci.degraded) .. [[
${else}${if_match ${cpu cpu0}<=100}
    ]] .. _h.value('${cpu cpu0}%', ci.bad) .. [[
${endif}${endif}${endif}
]]

-- Battery
parts.battery = _h.common('', 'BAT') .. [[,
${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}
]]

-- Template
parts.template = [[
]] .. _h.separator() .. [[,
]] .. _h.icon('') .. [[,
]] .. _h.text('') .. [[,
]] .. _h.value('', '#aaaaaa') .. [[
]]