Update of conkyrc from Fossa64 to the new Conky's Lua syntax

Issues and / or general discussion relating to Puppy

Moderator: Forum moderators

Post Reply
User avatar
user1234
Posts: 414
Joined: Sat Feb 26, 2022 5:48 am
Location: Somewhere on earth
Has thanked: 155 times
Been thanked: 90 times

Update of conkyrc from Fossa64 to the new Conky's Lua syntax

Post by user1234 »

I am currently working on adding conky in Jammy64. Since this version of conky uses Lua rather than the previous conkyrc's syntax, I have updated the conkyrc to the newer syntax.

Also, since Lua is a real programming language rather than simple conky stuff, we can do much more with it than we can with older conky. So, I've also updated the 'Filesystems' and 'NET' sections of conkyrc which earlier was simply a static list of mounts / net devices to a newer one not requiring that sort of code.

I present this conkyrc to you so that you can help in improving it. The mounted filesystems and network devices which are UP are found when conky starts up. The filesystems one can be made to update every time conky is updated, but this will require an additional bit of processing each time conky updates (I ask your opinion on whether this should be done).


Limitations:

  1. This version does not include the weather stuff.

  2. The Puppy's GUI to edit conky settings, as is in Fossa64, might not work out of the box on this conkyrc.

  3. I have not been able to successfully get a transparent background for it in Jammy64.

  4. Devices that are mounted at some path containing spaces (very rare in Puppy) might not work.


Additional commands required by this version are:

  1. ip

  2. lsblk

  3. awk

  4. grep


Here is the conkyrc:

Code: Select all

-- This is an update of older conkyrc found in Fossa64 to Conky's new Lua syntax.
-- Configs are save in `conky.config`; the text to be displayed is stored in `conky.text`

-- Lua uses `--` as comments. Comment out any line to disable that config.
-- Inside `conky.text`, the comments still are used with `#`.

-- Conky documentation can be found here:
--    Variables (in text) = https://conky.cc/variables
--    Config Settings     = https://conky.cc/config_settings
--    Lua API             = https://conky.cc/lua

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

-- show_mounts : template for filesystem
-- usage : see https://unix.stackexchange.com/a/768938/540879

function conky_show_mounts()
    -- Run the following lsblk command to get the device names and their mounted locations (except loop devices)
    local command = "lsblk --raw --noheadings -o NAME,MOUNTPOINT -e7 | awk '$1~/[[:digit:]]/ && $2 != \"\"' | grep -v -i 'swap'"

-- print(command) -- Uncomment to debug

-- Execute the command and capture the output
local handle = io.popen(command)
local output = handle:read("*a")
handle:close()

local result = "" -- The final result will be concatenated to this string

-- Process the output in Lua
for line in output:gmatch("[^\r\n]+") do
   local mount_name, mount_point = line:match('(%S+)%s*(%S*)')
    -- print(mount_name) -- uncomment to debug
    -- print(mount_point) -- uncomment to debug

    -- Add this mount {name, point} to result
    if mount_name and mount_point then -- our cmd also outputs devnames which don't have mountpoints; ignore them
        result = result .. "\n${color2}" .. mount_name .. " ${fs_used " .. mount_point .. "} / ${fs_size " ..
                 mount_point .. "} ${alignr}${color1}${fs_bar 10,120 " .. mount_point .. "}"
    end
end

return result
end

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

-- conky_show_netdevs : template for network
-- usage : see https://unix.stackexchange.com/a/768938/540879

function conky_show_netdevs()
    local netdevs_handle = io.popen("ip -o link show up | grep -v lo | grep -v -i 'state down' | awk '{print $2}' | cut -d':' -f1")
    local result = ""

for netdev in netdevs_handle:lines() do
    result = result .. "\nIP (${color1}" .. netdev .. "${color2}): ${alignr}${addr " .. netdev .. "}\n" ..
             "${color2}Up: ${color2}${upspeed " .. netdev .. "}/s${color1}${alignr}${upspeedgraph " .. netdev .. " 10,170}\n" ..
             "${color2}Down: ${color2}${downspeed " .. netdev .. "}/s${color1}${alignr}${downspeedgraph " .. netdev .. " 10,170}\n" ..
             "${color2}Total Down: ${color2}${totaldown " .. netdev .. "}${alignr}Total Up: ${totalup " .. netdev .. "}\n"
end

netdevs_handle:close()

if result ~= "" then
    return result
else
    return "\n"
end
end

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

conky.config = {
	use_xft = true, -- use xft?
	font = 'DejaVuSans:size=9', -- font name
	xftalpha = 1,
	uppercase = false, -- all text in uppercase?
	pad_percents = 0,
	text_buffer_size = 2048,
	override_utf8_locale = true, -- Force UTF8? note that UTF8 support required XFT
	use_spacer = 'none', -- Add spaces to keep things from moving about?  This only affects certain objects.

update_interval = 1, -- Update interval in seconds
double_buffer = true, -- Use double buffering (reduces flicker, may not work for everyone)
total_run_times = 0, -- This is the number of times Conky will update before quitting. Set to zero to run forever.

-- background = true, -- Run in background (same as running conky &)

-- Create own window instead of using desktop (required in nautilus)
own_window = true,
own_window_class = 'Conky',
own_window_transparent = true,
own_window_argb_visual = true,
own_window_argb_value = 255,
own_window_type = 'desktop',
own_window_hints = 'undecorated,sticky,below,skip_taskbar,skip_pager',

-- Minimum size of text area
minimum_height = 50,
minimum_width = 280,

draw_shades = false, -- draw shades?
draw_outline = false, -- draw outlines?
draw_borders = false, -- draw borders around text?
draw_graph_borders = false, -- draw borders around graphs
stippled_borders = 0, -- stripled borders?

imlib_cache_size = 0, -- Imlib2 image cache size, in bytes. Increase this value if you use $image lots. Set to 0 to disable the image cache.

-- Gap between borders of screen and text. Same thing as passing -x at command line
gap_x = 90,
gap_y = 5,

alignment = 'middle_right', -- alignment on {y_axis}_{x_axis}

cpu_avg_samples = 2, -- number of cpu samples to average. set to 1 to disable averaging
net_avg_samples = 2, -- number of net samples to average. set to 1 to disable averaging

no_buffers = true, -- Subtract file system buffers from used memory?

default_color = 'e0e0e0',
default_shade_color = '000000',
default_outline_color = '000000',

temperature_unit = 'celsius',

color1 = 'ff55ff', -- heading's color
color2 = 'ffffff', -- normal text's color
-- weather1 = 'liverpool', -- @todo
};

conky.text = [[
${color1}System ${hr 2}
${color2}${nodename}
#${color}${pre_exec cat /etc/DISTRO_SPECS | grep DISTRO_NAME | cut -d'"' -f2} # ${pre_exec} is deprecated in newer conky, use `execi [SOME BIG VALUE]` instead
${color2}${texeci 36000 cat /etc/DISTRO_SPECS | grep DISTRO_NAME | cut -d'"' -f2}
${color2}${sysname} ${kernel}
${color2}Uptime ${uptime}

${color1}Processes ${hr 2}
${color1}${alignr}CPU% used
${color2}${top name 1}${alignr}${top cpu 1} %
${color2}${top name 2}${alignr}${top cpu 2} %
${color2}${top name 3}${alignr}${top cpu 3} %
${color2}${top name 4}${alignr}${top cpu 4} %
#${color2}${top name 5}${alignr}${top cpu 5} %
#${color2}${top name 6}${alignr}${top cpu 6} %
#${color2}${top name 7}${alignr}${top cpu 7} %
${color1}${alignr}Mem used
${color2}${top_mem name 1}${alignr}${top_mem mem_res 1}
${color2}${top_mem name 2}${alignr}${top_mem mem_res 2}
${color2}${top_mem name 3}${alignr}${top_mem mem_res 3}
${color2}${top_mem name 4}${alignr}${top_mem mem_res 4}
#${color2}${top_mem name 5}${alignr}${top_mem mem_res 5}
#${color2}${top_mem name 6}${alignr}${top_mem mem_res 6}
#${color2}${top_mem name 7}${alignr}${top_mem mem_res 7}

${color1}Resources ${hr 2}
#${hwmon 3 temp 1}
${color2}CPU0: ${cpu cpu0}%${alignr}${color1}${cpubar cpu0 10,120}
#${color2}CPU1: ${cpu cpu1}%${alignr}${color1}${cpubar cpu1 10,120}
#${color2}CPU2: ${cpu cpu2}%${alignr}${color1}${cpubar cpu2 10,120}
#${color2}CPU3: ${cpu cpu3}%${alignr}${color1}${cpubar cpu3 10,120}
#${color2}CPU4: ${cpu cpu4}%${alignr}${color1}${cpubar cpu4 10,120}
#${color2}CPU5: ${cpu cpu5}%${alignr}${color1}${cpubar cpu5 10,120}
#${color2}CPU6: ${cpu cpu6}%${alignr}${color1}${cpubar cpu6 10,120}
${color2}Mem: ${mem} / ${memmax}
${memperc}% ${alignr}${color1}${membar 10,120}
${color2}Swap: ${swap} / ${swapmax}
${swapperc}% ${alignr}${color1}${alignr}${swapbar 10,120}
#${color2}Bat: ${battery} ${alignr}${color1}${battery_bar 10,120}

${color1}File Systems ${hr 2}]]

conky.text = conky.text .. conky_show_mounts() -- thanks to https://unix.stackexchange.com/a/768938/540879!

conky.text = conky.text .. [[


${color1}NET: ${hr 2}${color2}]]

conky.text = conky.text .. conky_show_netdevs() -- thanks to https://unix.stackexchange.com/a/768938/540879!

conky.text = conky.text .. [[EXT: ${alignr}  ${texeci 3600 wget -O - -q icanhazip.com}
####don't write below this line as used for conky gui weather
${color1}${voffset 2}${hr 2}
#
#
#
]]

Here is a screenshot:

Screenshot_20240210_205743.png
Screenshot_20240210_205743.png (63.68 KiB) Viewed 224 times
Last edited by user1234 on Wed Feb 14, 2024 9:31 am, edited 2 times in total.

PuppyLinux 🐾 gives new life to old computers ✨

User avatar
user1234
Posts: 414
Joined: Sat Feb 26, 2022 5:48 am
Location: Somewhere on earth
Has thanked: 155 times
Been thanked: 90 times

Re: Update of conkyrc from Fossa64 to the new Conky's Lua syntax

Post by user1234 »

New Update

I decided to allow filesystems to be updated every 5 seconds; and using all network devices, which based on whether they are UP or not will be displayed.


Here is the updated conkyrc:

Code: Select all

-- This is an update of older conkyrc found in Fossa64 to Conky's new Lua syntax.
-- Configs are save in `conky.config`; the text to be displayed is stored in `conky.text`

-- Lua uses `--` as comments. Comment out any line to disable that config.
-- Inside `conky.text`, the comments still are used with `#`.

-- Conky documentation can be found here:
--    Variables (in text) = https://conky.cc/variables
--    Config Settings     = https://conky.cc/config_settings
--    Lua API             = https://conky.cc/lua

-- conky_show_netdevs : template for network
-- usage : see https://unix.stackexchange.com/a/768938/540879

function conky_show_netdevs()
    local netdevs_handle = io.popen("ip -o link show up | grep -v lo | awk '{print $2}' | cut -d':' -f1")
    local result = ""

for netdev in netdevs_handle:lines() do
    result = result .. "${if_up " .. netdev .. "}${if_match ${execi 5 ip -o link show " .. netdev ..
             " | grep -i -v 'state down' | wc -l} > 0}\n" ..
             "IP (${color1}" .. netdev .. "${color2}): ${alignr}${addr " .. netdev .. "}\n" ..
             "${color2}Up: ${color2}${upspeed " .. netdev .. "}/s${color1}${alignr}${upspeedgraph " .. netdev .. " 10,170}\n" ..
             "${color2}Down: ${color2}${downspeed " .. netdev .. "}/s${color1}${alignr}${downspeedgraph " .. netdev .. " 10,170}\n" ..
             "${color2}Total Down: ${color2}${totaldown " .. netdev .. "}${alignr}Total Up: ${totalup " .. netdev .. "}${endif}${endif}"
end

netdevs_handle:close()

if result ~= "" then
    return result
else
    return ""
end
end

conky.config = {
	use_xft = true, -- use xft?
	font = 'DejaVuSans:size=9', -- font name
	xftalpha = 1,
	uppercase = false, -- all text in uppercase?
	pad_percents = 0,
	text_buffer_size = 2048,
	override_utf8_locale = true, -- Force UTF8? note that UTF8 support required XFT
	use_spacer = 'none', -- Add spaces to keep things from moving about?  This only affects certain objects.

update_interval = 1, -- Update interval in seconds
double_buffer = true, -- Use double buffering (reduces flicker, may not work for everyone)
total_run_times = 0, -- This is the number of times Conky will update before quitting. Set to zero to run forever.

-- background = true, -- Run in background (same as running conky &)

-- Create own window instead of using desktop (required in nautilus)
own_window = true,
own_window_class = 'Conky',
own_window_transparent = true,
own_window_argb_visual = true,
own_window_argb_value = 255,
own_window_type = 'desktop',
own_window_hints = 'undecorated,sticky,below,skip_taskbar,skip_pager',

-- Minimum size of text area
minimum_height = 50,
minimum_width = 280,

draw_shades = false, -- draw shades?
draw_outline = false, -- draw outlines?
draw_borders = false, -- draw borders around text?
draw_graph_borders = false, -- draw borders around graphs
stippled_borders = 0, -- stripled borders?

imlib_cache_size = 0, -- Imlib2 image cache size, in bytes. Increase this value if you use $image lots. Set to 0 to disable the image cache.

-- Gap between borders of screen and text. Same thing as passing -x at command line
gap_x = 90,
gap_y = 5,

alignment = 'middle_right', -- alignment on {y_axis}_{x_axis}

cpu_avg_samples = 2, -- number of cpu samples to average. set to 1 to disable averaging
net_avg_samples = 2, -- number of net samples to average. set to 1 to disable averaging

no_buffers = true, -- Subtract file system buffers from used memory?

default_color = 'e0e0e0',
default_shade_color = '000000',
default_outline_color = '000000',

temperature_unit = 'celsius',

color1 = 'ff55ff', -- heading's color
color2 = 'ffffff', -- normal text's color
-- weather1 = 'liverpool', -- @todo

    lua_load = 'show_mounts.lua',
};

conky.text = [[
${color1}System ${hr 2}
${color2}${nodename}
#${color}${pre_exec cat /etc/DISTRO_SPECS | grep DISTRO_NAME | cut -d'"' -f2} # ${pre_exec} is deprecated in newer conky, use `execi [SOME BIG VALUE]` instead
${color2}${texeci 36000 cat /etc/DISTRO_SPECS | grep DISTRO_NAME | cut -d'"' -f2}
${color2}${sysname} ${kernel}
${color2}Uptime ${uptime}

${color1}Processes ${hr 2}
${color1}${alignr}CPU% used
${color2}${top name 1}${alignr}${top cpu 1} %
${color2}${top name 2}${alignr}${top cpu 2} %
${color2}${top name 3}${alignr}${top cpu 3} %
${color2}${top name 4}${alignr}${top cpu 4} %
#${color2}${top name 5}${alignr}${top cpu 5} %
#${color2}${top name 6}${alignr}${top cpu 6} %
#${color2}${top name 7}${alignr}${top cpu 7} %
${color1}${alignr}Mem used
${color2}${top_mem name 1}${alignr}${top_mem mem_res 1}
${color2}${top_mem name 2}${alignr}${top_mem mem_res 2}
${color2}${top_mem name 3}${alignr}${top_mem mem_res 3}
${color2}${top_mem name 4}${alignr}${top_mem mem_res 4}
#${color2}${top_mem name 5}${alignr}${top_mem mem_res 5}
#${color2}${top_mem name 6}${alignr}${top_mem mem_res 6}
#${color2}${top_mem name 7}${alignr}${top_mem mem_res 7}

${color1}Resources ${hr 2}
#${hwmon 3 temp 1}
${color2}CPU0: ${cpu cpu0}%${alignr}${color1}${cpubar cpu0 10,120}
#${color2}CPU1: ${cpu cpu1}%${alignr}${color1}${cpubar cpu1 10,120}
#${color2}CPU2: ${cpu cpu2}%${alignr}${color1}${cpubar cpu2 10,120}
#${color2}CPU3: ${cpu cpu3}%${alignr}${color1}${cpubar cpu3 10,120}
#${color2}CPU4: ${cpu cpu4}%${alignr}${color1}${cpubar cpu4 10,120}
#${color2}CPU5: ${cpu cpu5}%${alignr}${color1}${cpubar cpu5 10,120}
#${color2}CPU6: ${cpu cpu6}%${alignr}${color1}${cpubar cpu6 10,120}
${color2}Mem: ${mem} / ${memmax}
${memperc}% ${alignr}${color1}${membar 10,120}
${color2}Swap: ${swap} / ${swapmax}
${swapperc}% ${alignr}${color1}${alignr}${swapbar 10,120}
#${color2}Bat: ${battery} ${alignr}${color1}${battery_bar 10,120}

${color1}File Systems ${hr 2}${lua conky_show_mounts}

${color1}NET: ${hr 2}${color2}]]

conky.text = conky.text .. conky_show_netdevs() -- thanks to https://unix.stackexchange.com/a/768938/540879!

conky.text = conky.text .. [[

EXT: ${alignr}  ${texeci 3600 wget -O - -q icanhazip.com}
####don't write below this line as used for conky gui weather
${color1}${voffset 2}${hr 2}
#
#
#
]]

It also requires additional lua file show_mounts.lua, which needs to be placed in $PWD (yes, run conky from the directory where you place this lua file):

Code: Select all

-- show_mounts : template for filesystem
-- notes : updates after every 5 conky updates
-- usage : ${lua conky_show_mounts}

cached_conky_show_mount_output = nil

function conky_show_mounts()
    local updates = tonumber(conky_parse("${updates}"))
    local interval = 5 -- number of conky updates after which this function should be updated
                       -- in seconds, this is equal to (interval * conky's update_interval)

if (updates%interval ~= 0) and (cached_conky_show_mount_output ~= nil) then
    -- print('cached') -- uncomment to debug
    -- print(cached_conky_show_mount_output) -- uncomment to debug
    return conky_parse(cached_conky_show_mount_output)
end

-- Run the following lsblk command to get the device names and their mounted locations (except loop devices)
local command = "lsblk --raw --noheadings -o NAME,MOUNTPOINT -e7 | awk '$1~/[[:digit:]]/ && $2 != \"\"' | grep -v -i 'swap'"

-- print(command) -- Uncomment to debug

-- Execute the command and capture the output
local handle = io.popen(command)
local output = handle:read("*a")
handle:close()

local result = "" -- The final result will be concatenated to this string

-- Process the output in Lua
for line in output:gmatch("[^\r\n]+") do
   local mount_name, mount_point = line:match('(%S+)%s*(%S*)')
    -- print(mount_name) -- uncomment to debug
    -- print(mount_point) -- uncomment to debug

    -- Add this mount {name, point} to result
    if mount_name and mount_point then -- our cmd also outputs devnames which don't have mountpoints; ignore them
        result = result .. "\n${color2}" .. mount_name .. " ${fs_used " .. mount_point .. "} / ${fs_size " ..
                 mount_point .. "} ${alignr}${color1}${fs_bar 10,120 " .. mount_point .. "}"
    end
end

-- print('reloaded') -- uncomment to debug
cached_conky_show_mount_output = result

return conky_parse(cached_conky_show_mount_output)
end

Here is a display of the above update:

i) Filesystem:

ii) Network devices:

Last edited by user1234 on Wed Feb 14, 2024 10:38 am, edited 2 times in total.

PuppyLinux 🐾 gives new life to old computers ✨

User avatar
user1234
Posts: 414
Joined: Sat Feb 26, 2022 5:48 am
Location: Somewhere on earth
Has thanked: 155 times
Been thanked: 90 times

Re: Update of conkyrc from Fossa64 to the new Conky's Lua syntax

Post by user1234 »

Please everyone viewing this and has access to new lua, please test this and report me if it doesn't work for you. Once completed, I want to incorporate this in woof-CE.


EDIT:

Unless any new improvements should be made here, or if anyhow we can overcome those limitations, this should just work fine. I have tried to update conky-gtk to make it usable with this - changing colors, changing font {size, family}, restarting/stopping conky, enabling/disabling autostart - these functions I have tested successfully. The remaining are backup and weather (which I could not test today, but I don't think many changes will be required there).

I'll upload the updated conky-gtk tomorrow once completed; for today, I am already too sleepy to do so 🥱🥱.

Regards
Lakshay :thumbup2:

PuppyLinux 🐾 gives new life to old computers ✨

User avatar
rockedge
Site Admin
Posts: 6542
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2749 times
Been thanked: 2620 times
Contact:

Re: Update of conkyrc from Fossa64 to the new Conky's Lua syntax

Post by rockedge »

@user1234 I have the conkyrc and show_mounts.lua set up in a F96-CE_4-RT and so far working but background transparency is not working. The updating of the Conky display on current filesystem information and the other functions as expected. :thumbup:

I changed the bar colors and added in the weather function.

Screenshot(1).gif
Screenshot(1).gif (85.12 KiB) Viewed 308 times
User avatar
user1234
Posts: 414
Joined: Sat Feb 26, 2022 5:48 am
Location: Somewhere on earth
Has thanked: 155 times
Been thanked: 90 times

Re: Update of conkyrc from Fossa64 to the new Conky's Lua syntax

Post by user1234 »

rockedge wrote: Sun Feb 11, 2024 8:34 pm

@user1234 I have the conkyrc and show_mounts.lua set up in a F96-CE_4-RT and so far working
Screenshot(1).gif

@rockedge, thanks for testing! :thumbup:


... but background transparency is not working. ...

Yes, I am, by far, not able to get the transparency working.


I changed the bar colors and added in the weather function.

Weather should just work fine - I'll get the conky-gtk updated and it should be all right :thumbup:


One thing I noticed - while the text should have simply been fossapup64, you got DISTRO_NAME='fossapup64. I see why this happens - the conkyrc cats the /etc/DISTRO_SPECS (found in I think all puppies), gets the DISTRO_NAME line, extracts the value of distro name from quotes. The problem is that the current script only works with double quotes, while your DISTRO_SPECS file uses single quotes around its value. I'll update the conkyrc to resolve this issue.

PuppyLinux 🐾 gives new life to old computers ✨

Post Reply

Return to “Users”