Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a strange issue with my Conky setup:

enter image description here

What I'm looking to get rid of/fix is the fact that my CPU percentages (using ${cpu cpuX}) won't seem to pad properly. I'd like all values to be aligned vertically so that statuses never wiggle. Here's excerpts from my conky file:

# ...
pad_percents 3
# ...
${cpubar cpu1 6,135}$alignr${...}${cpu cpu1}%

How can I right align and pad CPU percentage values so they stop throwing off my layout? The equivalent printf would be %3.0f so that values will appear like this:

$ "%3.0f" % (1,) 
'  1'
$ "%3.0f" % (13,)
' 13'
$ "%3.0f" % (100,)

How can I make this happen in Conky for my CPU percentage?

share|improve this question
See: superuser.com/questions/178179/… – jasonwryan Dec 6 '12 at 21:07
Thanks, I wrote a Lua printf function which takes a format string and a value, works great! Only thing now is to set a monospace fonnt so we never see a wiggle due to difference in character widths. – Naftuli Tzvi Kay Dec 6 '12 at 21:17
up vote 4 down vote accepted

A solution provided by @jasonwryan above:

  1. Create a Lua script for Conky to use. I created mine in a folder I made in ~/.config/conky/scripts, but you can create yours wherever you'd like:

    $ mkdir -p ~/.config/conky/scripts/
    $ vim ~/.config/conky/scripts/conky_lua_scripts.lua
  2. Fill the file with the following Lua function:

    function conky_format( format, number )
        return string.format( format, conky_parse( number ) )
  3. Import your Lua script file into your Conky configuration file using the lua_load directive

    # ...
    lua_load ~/.config/conky/scripts/conky_lua_scripts.lua
    # ...
  4. Whenever you'd like to format a value, call the format function we defined earlier. Note that though we named it conky_format, we access it as format using the lua_parse variable:

    # ...
    lua_load ~/.config/conky/scripts/conky_lua_scripts.lua
    # ...
    ${lua_parse format %3.0f ${cpu cpu1}}%

This nice script allows you to call into Lua formatting engine with any value and format string. The output now looks as expected:


If you're familiar with printf, you can use the utility to do other awesome formatting hacks.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.