Talk:Conky/Tips and tricks

From ArchWiki

Migration from main Conky article

I have moved the tips and tricks section from the main conky article to here, but the tips need to be verified as still relevant and working. I have not tested them all out. I know checkupdates and rss works, I have not looked at the mail scripts nor weather or anything else. I have a feeling the weather section may be out of date. Meskarune (talk) 22:02, 14 March 2018 (UTC)Reply[reply]

Display a calendar for the current month - suggesting lua file fix

Having used the lua file mentioned in the Arch wiki for displaying the calendar for the current month, I would suggest changing the lua file to the following:


#!/usr/bin/env lua


conky_color = "${color1}%2d${color}"

conky_color2 = "${color1} %2d${color}"


t = os.date('*t', os.time())

year, month, currentday = t.year, t.month, t.day


daystart = os.date("*t",os.time{year=year,month=month,day=01}).wday


month_name = os.date("%B")


days_in_month = {

    31, 28, 31, 30, 31, 30,

    31, 31, 30, 31, 30, 31

}


-- check for leap year

-- Any year that is evenly divisible by 4 is a leap year

-- Any year that is evenly divisible by 100 is a leap year if

-- it is also evenly divisible by 400.

LeapYear = function (year)

    return year % 4 == 0 and (year % 100 ~= 0 or year % 400 == 0)

end


if LeapYear(year) then

    days_in_month[2] = 29

end


title_start = (20 - (string.len(month_name) + 5)) / 2


title = string.rep(" ", math.floor(title_start+0.5)) .. -- add padding to center the title

        (" %s %s\n Su Mo Tu We Th Fr Sa\n"):format(month_name, year)


io.write(title)


function seq(a,b)

    if a > b then

        return

    else

        return a, seq(a+1,b)

    end

end


days = days_in_month[month]


-- If the current day is on either 1, 2 or 3, then highlight only that day.

-- This additional section is necessary; otherwise, other extraneous numbers become highlighted.

if (currentday == 1 or currentday == 2 or currentday == 3)

then

    io.write(

        string.format(

            string.rep("   ", daystart-1) ..

            string.rep(" %2d", days), seq(1,days)

        ):gsub(string.rep(".",21),"%0\n")

         :gsub((" %2d"):format(currentday),

               (conky_color2):format(currentday)

          ) .. "\n"

    )

else

    io.write(

        string.format(

            string.rep("   ", daystart-1) ..

            string.rep(" %2d", days), seq(1,days)

        ):gsub(string.rep(".",21),"%0\n")

         :gsub(("%2d"):format(currentday),

               (conky_color):format(currentday)

          ) .. "\n"

    )

end


Notice that I added a new variable named "conky_color2". I also added an additional section that displays conky output differently if the current day is on either 1, 2 or 3 (ex. May 1, May 2 or May 3). Otherwise, conky highlights all the days with "1", or "2", or "3" (ex. if the current day is March 1, then conky will highlight 1, 10, 11, 12, ... 19, 21, 31). Isaackwy (talk) 08:48, 25 February 2024 (UTC)Reply[reply]