lcpz / lain

Awesome WM complements
GNU General Public License v2.0
1.05k stars 212 forks source link

Uptime widget #520

Closed nenikitov closed 2 years ago

nenikitov commented 2 years ago

Implemented a widget that gets the info about system's uptime.

lcpz commented 2 years ago

Thank you for your interest in my repository, and for taking the time to write this widget.

Unfortunately, I cannot accept it because what you want can be easily achieved with a watcher like this:

local floor = math.floor
local uptime = awful.widget.watch(
    'bash -c "cat /proc/uptime | cut -d\' \' -f1"',
    1, -- refresh rate (in seconds)
    function(widget, stdout)
        local seconds = floor(stdout)
        local minutes = floor(seconds / 60) % 60
        local hours   = floor(seconds / 3600) % 24
        local days    = floor(seconds / 86400)

        seconds = seconds % 60

        -- customize here
        widget:set_text(string.format(
            "Uptime: %02d:%02d:%02d:%02d", days, hours, minutes, seconds)
        )
    end
)

The reason for prioritising watchers is that awful.widget.watch is supported officially, while my repository is not.

Feel free to add this code to the Recipes section of the AwesomeWM website.