i know that you are good in lua language pleas help me with conky and lua configuration. prepare me conky widget like in the input " 14:35
[######################..............] (60% of day)
code
Wednesday, April 05
[##########..........................] (33% of month)
code
2025 week 30'th
[###################.................] (55% of year)" it present time date and week of the year and horizontal bars depicting passing by time
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Bars are 36 characters long (matching your example's length inside the brackets), using # for filled and . for empty. The number of # is rounded (math.floor(perc/100 * 36 + 0.5)).
Why the Month Percentage Doesn't Match Your Example Exactly: In your example, "April 05" with "33% of month" doesn't align with standard calculations (April has 30 days, so ~15-17% passed on the 5th at 14:35). It might be a typo or illustrative data (e.g., perhaps meant to be April 10, where 10/30 ≈ 33%). I've used the logical/accurate calculation above. If you want a different formula (e.g., month_number / 12 * 100 = 33% for April), let me know and I can adjust.
Dependencies: This requires Conky 1.10+ with Lua support (most modern versions have it).
Customization: Indents match your example. Bar length is 36 (inside []), but you can change it in the Lua script.
Testing: This will show current time/date values, not the exact example values (since it's dynamic).
Step 1: Conky Configuration
Create or edit your ~/.conkyrc (or a dedicated file like ~/.conky/time_widget.conkyrc). Add the following. This is a minimal standalone config for the widget—you can integrate it into a larger Conky setup.
code
conky.config = {
alignment = 'top_left', -- Position on screen (adjust as needed)
background = false,
border_width = 0,
cpu_avg_samples = 2,
default_color = 'white',
default_outline_color = 'white',
default_shade_color = 'white',
double_buffer = true,
draw_borders = false,
draw_graph_borders = true,
draw_outline = false,
draw_shades = false,
extra_newline = false,
font = 'DejaVu Sans Mono:size=12', -- Adjust font/size as needed
gap_x = 50, -- X position
gap_y = 50, -- Y position
minimum_height = 5,
minimum_width = 5,
net_avg_samples = 2,
no_buffers = true,
out_to_console = false,
out_to_ncurses = false,
out_to_stderr = false,
out_to_x = true,
own_window = true,
own_window_class = 'Conky',
own_window_type = 'desktop', -- Or 'normal' if you want it in a window
stippled_borders = 0,
update_interval = 1.0, -- Update every second for smooth progress
uppercase = false,
use_spacer = 'none',
use_xft = true,
-- Load the Lua script (adjust path if needed)
lua_load = '~/.conky/scripts/time_progress.lua',
}
conky.text = [[
${lua conky_time_progress ${time %H} ${time %M} ${time %S} ${time %A} ${time %B} ${time %d} ${time %Y} ${time %W} ${time %m} ${time %j}}
]]
Explanation: The ${lua ...} line calls the Lua function with Conky variables (e.g., ${time %H} for hour). The function returns the entire formatted block as a string with newlines.
Step 2: Lua Script
Create a file at ~/.conky/scripts/time_progress.lua (create the scripts folder if needed). Paste the following code:
lua
function conky_time_progress(h_str, m_str, s_str, weekday, monthname, day_str, year_str, week_str, month_str, yday_str)
-- Convert strings to numbers
local hour = tonumber(h_str)
local min = tonumber(m_str)
local sec = tonumber(s_str)
local day = tonumber(day_str)
local year = tonumber(year_str)
local week = tonumber(week_str)
local month = tonumber(month_str)
local yday = tonumber(yday_str) -- Day of year (1-366)
-- Calculate day fraction (0.0 to 1.0)
local day_fraction = (hour * 3600 + min * 60 + sec) / 86400
-- Day percentage
local day_perc = day_fraction * 100
-- Month percentage
local days_in_month = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
local is_leap = (year % 4 == 0 and (year % 100 ~= 0 or year % 400 == 0))
if month == 2 and is_leap then days_in_month[2] = 29 end
local month_perc = ((day - 1) + day_fraction) / days_in_month[month] * 100
-- Year percentage
local days_in_year = is_leap and 366 or 365
local year_perc = ((yday - 1) + day_fraction) / days_in_year * 100
-- Function to generate progress bar
local function make_bar(perc)
local bar_len = 36 -- Matches example length inside []
local filled = math.floor((perc / 100) * bar_len + 0.5)
if filled > bar_len then filled = bar_len end
if filled < 0 then filled = 0 end
return "[" .. string.rep("#", filled) .. string.rep(".", bar_len - filled) .. "]"
end
-- Formatted percentage strings
local day_pct_str = string.format("(%d%% of day)", math.floor(day_perc + 0.5))
local month_pct_str = string.format("(%d%% of month)", math.floor(month_perc + 0.5))
local year_pct_str = string.format("(%d%% of year)", math.floor(year_perc + 0.5))
-- Time string (HH:MM, no seconds as in example)
local time_str = string.format("%02d:%02d", hour, min)
-- Date string
local date_str = weekday .. ", " .. monthname .. " " .. day_str
-- Week string with proper suffix (st, nd, rd, th)
local week_suffix = "th"
local week_last_digit = week % 10
if week_last_digit == 1 then week_suffix = "st"
elseif week_last_digit == 2 then week_suffix = "nd"
elseif week_last_digit == 3 then week_suffix = "rd" end
local week_full_str = year_str .. " week " .. week_str .. week_suffix
-- Build the output string with indents and newlines matching the example
local output = ""
output = output .. string.rep(" ", 15) .. time_str .. "\n"
output = output .. make_bar(day_perc) .. " " .. day_pct_str .. "\n"
output = output .. "\n" -- Extra newline for spacing
output = output .. string.rep(" ", 10) .. date_str .. "\n"
output = output .. make_bar(month_perc) .. " " .. month_pct_str .. "\n"
output = output .. "\n" -- Extra newline for spacing
output = output .. string.rep(" ", 12) .. week_full_str .. "\n"
output = output .. make_bar(year_perc) .. " " .. year_pct_str
return output
end
Step 3: Running It
Save the files.
Make the Lua script executable (optional but good practice): chmod +x ~/.conky/scripts/time_progress.lua.
Run Conky: conky -c ~/.conky/time_widget.conkyrc (adjust path if needed).
If it doesn't appear, ensure Conky is installed and check for errors with conky -v or by running in terminal.
Example Output (Simulated for Current Time)
Assuming current time is ~14:35 on Wednesday, April 5, 2024 (a non-leap year, week ~14), it might look like:
code
14:35
[######################..............] (61% of day)
Wednesday, April 05
[#####...............................] (15% of month)
2024 week 14th
[##########..........................] (26% of year)
The bars and percentages will update every second.
If the month percentage needs to match your example's 33% exactly (e.g., using a different formula like month/12), provide more details and I'll tweak the Lua script.
If you encounter errors, need adjustments (e.g., colors, font, position, bar length, or calculation changes), or have issues with leap years/weeks, let me know!