Skip to content

Instantly share code, notes, and snippets.

@kkoch986
Last active October 14, 2018 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkoch986/368642010a6b2964259b640cf9980ceb to your computer and use it in GitHub Desktop.
Save kkoch986/368642010a6b2964259b640cf9980ceb to your computer and use it in GitHub Desktop.
my WIP dzen / conky status bar
conky.config = {
out_to_x = false,
out_to_console = true,
update_interval = 1.0,
total_run_times = 0,
use_spacer = none,
use_xft = true,
override_utf8_locale = true,
font = 'Terminus:style = Regular:pixelsize=24:antialias=true'
}
---------------------------------
-- Static Colors
---------------------------------
local lightGrey = "\\#bcbcbc"
local darkGrey = "\\#262626"
local green = "\\#b5bd68"
local red = "\\#cc6666"
local yellow = "\\#f0c674"
---------------------------------
-- Utils
---------------------------------
-- the powerline left arrow (need to swap FG and BG colors first)
local arrow = "^fn(powerlinesymbols-12)^fn()"
local thinArrow = "^fn(powerlinesymbols-12)^fn()"
-- returns a string which will set the colors for dzen (^fg and ^bg)
function setColor(fg, bg)
return "^fg(" .. fg .. ")^bg(" .. bg .. ")"
end
-- return a good font color for the given bg color.
function colorCompliment(col)
return darkGrey
end
---------------------------------
-- Dynamic Colors
---------------------------------
-- cutoffs must be provided in descending order
function setConditionalColor(field, cutoffs, reverse, alternateColor)
local ret = ""
local first = true
local endifs = ""
for p in ipairs(cutoffs) do
local color = cutoffs[p][1]
local cutoff = cutoffs[p][2]
if(alternateColor == nil) then
alternateColor = colorCompliment(color)
end
if(first ~= true) then
ret = ret .. "${else}"
end
ret = ret
.. "${if_match ${" .. field .."} >= " .. cutoff .. "}"
.. setColor(
reverse and color or alternateColor,
reverse and alternateColor or color)
endifs = endifs .. "${endif}";
first = false
end
ret = ret .. endifs
return ret
end
---------------------------------
-- Sections
---------------------------------
-- CPU / RAM
local iconCpu = "^i(.dzen/bitmap/cpu.xbm)"
local iconRam = "^i(.dzen/bitmap/mem.xbm)"
local elemCpu = " " .. iconCpu .. " ${cpu}% "
local elemRam = " " .. iconRam .. " ${memperc}% "
local cpuCutoffs = { { red, 75 }, { yellow, 50 }, { green, 0 } }
local memCutoffs = { { red, 75 }, { yellow, 50 }, { green, 0 } }
local sectionCpuRam =
setConditionalColor("cpu", cpuCutoffs, true)
.. arrow
.. setConditionalColor("cpu", cpuCutoffs, false)
.. elemCpu
.. setConditionalColor("memperc", memCutoffs, false)
.. elemRam
.. arrow
.. setConditionalColor("memperc", memCutoffs, true)
-- Networking
local wifiColorCutoffs = { { green, 75 }, { yellow, 50 }, { red, 0 } }
local iconWifiQuality =
setConditionalColor("wireless_link_qual_perc wlo1", wifiColorCutoffs, true)
.. "${if_match ${wireless_link_qual_perc wlo1} >= 75}"
.. "^i(/home/ken/.dzen/bitmap/wifi_strength_3.xbm)"
.. "${else}${if_match ${wireless_link_qual_perc wlo1} >= 50}"
.. "^i(/home/ken/.dzen/bitmap/wifi_strength_2.xbm)"
.. "${else}${if_match ${wireless_link_qual_perc wlo1} >= 25}"
.. "^i(/home/ken/.dzen/bitmap/wifi_strength_1.xbm)"
.. "${else}"
.. "^i(/home/ken/.dzen/bitmap/wifi_strength_0.xbm)"
.. "${endif}${endif}${endif}"
.. setColor(lightGrey, darkGrey)
local iconNetDown = "^i(/home/ken/.dzen/bitmap/net_down_01.xbm)"
local sectionWifi =
" ${if_up wlo1}"
.. iconWifiQuality .. " "
.. "${wireless_essid wlo1} "
.. "${endif}"
local sectionNetworking =
setColor(lightGrey,darkGrey)
.. iconNetDown .. " "
.. "${downspeedf wlo1} "
.. thinArrow
.. " ${addr wlo1} "
.. thinArrow
.. sectionWifi
-- Battery
-- TODO: use the icons for full / low / empty (or make a bar)
local iconFullBat = "^i(/home/ken/.dzen/bitmap/bat_full_01.xbm)"
local iconLowBat = "^i(/home/ken/.dzen/bitmap/bat_low_01.xbm)"
local iconEmptyBat = "^i(/home/ken/.dzen/bitmap/bat_empty_01.xbm)"
local iconPlug = "^i(/home/ken/.dzen/bitmap/plug.xbm)"
local elemBatteryTime = [[${if_match "${battery_time}" == ""}]]
..iconPlug.. " ${else} | ${battery_time} ${endif}"
local batteryCutOffs = { {green, 60}, {yellow, 10}, {red, 0} }
local sectionBattery =
setConditionalColor("battery_percent", batteryCutOffs, true)
.. arrow ..
setConditionalColor("battery_percent", batteryCutOffs, false)
.. " ${battery_percent}% " .. elemBatteryTime
---------------------------------
-- Output
---------------------------------
conky.text = sectionCpuRam .. sectionNetworking .. sectionBattery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment