Commit 59f8f66c authored by epsi sayidina's avatar epsi sayidina

standalone CLI conky lua

parent bdaf296a
-- vim: ts=4 sw=4 noet ai cindent syntax=lua
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- 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"
-- 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
}
-- load subroutine
home = os.getenv("HOME")
path = '/Documents/standalone/cli/conky/'
dofile(home .. path .. 'ansi.lua')
dofile(home .. path .. 'helper.lua')
dofile(home .. path .. 'parts.lua')
-- 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 .. [[
]]
-- vim: ts=4 sw=4 noet ai cindent syntax=lua-- global
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
#!/usr/bin/env bash
# hide cursor
tput civis -- invisible
# type' tput cnorm' to show
clear
conky -c ~/Documents/standalone/cli/conky/conky.lua
-- 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
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)
-- Template
--parts.template = [[
--]] .. _h.icon('') .. [[,
--]] .. _h.label('') .. [[,
--]] .. _h.value('', ansiSomething) .. [[
--]]
#!/usr/bin/env bash
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# for use with 'watch --color'
esc="\033"
fgRed="${esc}[31m"
fgBlue="${esc}[34m"
fgWhite="${esc}[37m"
bgRed="${esc}[41m"
bgBlue="${esc}[44m"
bgWhite="${esc}[47m"
complexBlue="${esc}[1;3;4;34m"
boldOn="${esc}[1m"
boldOff="${esc}[22m"
reset="${esc}[0m"
date=$(date +'%a %b %d')
time=$(date +'%H:%M:%S')
arrow="${boldOff}"
awesome='                '
text=""
text+="${fgBlue} ${date} "
text+="${complexBlue} ${time}"
text+="${reset}\n"
text+="${awesome}"
text+="${reset}\n"
text+="${bgBlue}${fgWhite}${arrow}"
text+="${bgBlue}${fgWhite}${boldOn} Right "
text+="${bgRed}${fgBlue}${arrow}"
text+="${bgRed}${fgWhite}${boldOn} Arrow "
text+="${reset}${fgRed}${arrow}"
text+="\n"
echo -e $text
#!/usr/bin/env bash
. ~/Documents/standalone/cli/example/ansi.sh
. ~/Documents/standalone/cli/example/helpercpu.sh
. ~/Documents/standalone/cli/example/progressbar.sh
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# test
initializeANSI
arrow="${boldOff}"
# hide cursor
tput civis -- invisible
# type' tput cnorm' to show
clear
while :; do
helperCPU
tput cup 0 0
echo ""
# cpu
value=$cpu_util
progressbar $value
percent=$(printf "[ %3d%% ]" $value)
diskText="${reset}"
diskText+=" CPU ${fgBlue}${boldOn}$percent${reset} "
diskText+=$progressBarText
echo -e "$diskText"
# disk
value=$(df /home -h | awk 'FNR == 2 {print $5}' | sed s/%//)
progressbar $value
percent=$(printf "[ %3d%% ]" $value)
diskText="${reset}"
diskText+=" Disk ${fgBlue}${boldOn}$percent${reset} "
diskText+=$progressBarText
echo -e "$diskText"
# date time
date=$(date +'%a %b %d')
time=$(date +'%H:%M:%S')
dateText="\n${reset} "
dateText+="${bgRed}${fgWhite}${arrow}"
dateText+="${bgRed}${fgWhite}${boldOn} ${date} "
dateText+="${bgWhite}${fgRed}${arrow}"
dateText+="${bgWhite}${fgRed} ${time} "
dateText+="${reset}${fgWhite}${arrow}"
dateText+="${reset}\n"
echo -e "$dateText"
# host
value=$(uname -n)
echo -e " ${fgRed}${reset}Host ${fgBlue}${boldOn}$value\n"
sleep 2
done
-- 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
}
-- Lua Function Demo
-- https://github.com/brndnmtthws/conky/issues/62
function 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 gototopleft()
return exec('tput cup 0 0')
end
conky.text = gototopleft() .. [[\
 ${time %a %b %d} -  ${time %H:%M:%S}\
]]
#!/usr/bin/env bash
# hide cursor
tput civis -- invisible
# type' tput cnorm' to show
clear
conky -c ~/Documents/standalone/cli/example/03.lua
#!/usr/bin/env bash
# https://github.com/marvins/Code_Sandbox/blob/master/bash/scripts/initializeANSI.bash
initializeANSI() {
esc="\033" # If this doesn't work, enter an ESC directly
# esc=""
# Foreground Colors
fgBlack="${esc}[30m"; fgRed="${esc}[31m"; fgGreen="${esc}[32m"
fgYellow="${esc}[33m"; fgBlue="${esc}[34m"; fgPurple="${esc}[35m"
fgCyan="${esc}[36m"; fgWhite="${esc}[37m";
# Background Colors
bgBlack="${esc}[40m"; bgRed="${esc}[41m"; bgGreen="${esc}[42m"
bgYellow="${esc}[43m"; bgBlue="${esc}[44m"; bgPurple="${esc}[45m"
bgCyan="${esc}[46m"; bgWhite="${esc}[47m";
# Special Character Conditions
boldOn="${esc}[1m"; boldOff="${esc}[22m"
italicsOn="${esc}[3m"; italicsOff="${esc}[23m"
underlineOn="${esc}[4m"; underlineOff="${esc}[24m"
invertOn="${esc}[7m"; invertOff="${esc}[27m"
# Reset to default configuration
reset="${esc}[0m"
}
helperCPU() {
# Read /proc/stat file (for first datapoint)
read cpu user nice system idle iowait irq softirq steal guest< /proc/stat
# compute active and total utilizations
local cpu_active_prev=$((user+system+nice+softirq+steal))
local cpu_total_prev=$((user+system+nice+softirq+steal+idle+iowait))
# echo 'cpu_active_prev = '.cpu_active_prev
sleep 1
# Read /proc/stat file (for second datapoint)
read cpu user nice system idle iowait irq softirq steal guest< /proc/stat
# compute active and total utilizations
local cpu_active_cur=$((user+system+nice+softirq+steal))
local cpu_total_cur=$((user+system+nice+softirq+steal+idle+iowait))
# compute CPU utilization (%)
cpu_util=$((100*( cpu_active_cur-cpu_active_prev ) / (cpu_total_cur-cpu_total_prev) ))
}
#!/usr/bin/env bash
# http://www.pavel-jiranek.net/simple-progress-bar-in-bash/
function progressbar() {
value=$1
# Default options.
max=100
width=25
symbol="="
# Compute the number of blocks to represent the percentage.
num=$(( value * width / max ))
# Create the progress bar string.
bar=''
if [ $num -gt 0 ]; then
bar=$(printf "%0.s${symbol}" $(seq 1 $num))
fi
# Print the progress bar.
line=$(printf "[%-${width}s]" "$bar")
progressBarText="${line}\r"
}
-- vim: ts=4 sw=4 noet ai cindent syntax=lua
-- for use white bright dzen2 panel
-- for use with bright dzen2 panel
deco = helper.decoDoubleArrowLeft
......
-- vim: ts=4 sw=4 noet ai cindent syntax=lua
-- for use white bright dzen2 panel
deco = helper.decoDoubleArrowLeft
--[[
disabled = ''
.. parts.mpd()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment