1

I have started using Conky some days ago, and I'm willing to create my own configuration. I have added some colors, cool ASCII art and learned the basics.

However, I don't like the default progress bars coming with Conky, and I would like to create something like a string of 50 '#' signs or 'rectangles' (219th character in the ASCII table), being the first 20 green, the following 20 yellow and the last 10 red.

I'd like to implement it as a fs_bar, being green when having plenty of free space, yellow when it's half full and red when I should free some files, but showing the three colours in the two last cases. I'm attaching an image with a pretty similar result.

I am running AwesomeWM in Arch Linux, and my Conky version is 1.10.5.

2

You can do something simple like this, which uses execpi to run a shell script every 30 seconds that parses the output of df / and converts it into a long string of conky color commands and \# characters (since # is used for comments):

${execpi 30  df --output=pcent / | awk 'NR==2 {
  n = ($1+0)/2; yellow = 20; red = 40;
  if(n>=red)   { r = "${color #ff0000}"; for(;n>=red;n--)   r = r "\\#" }
  if(n>=yellow){ y = "${color #ffff00}"; for(;n>=yellow;n--)y = y "\\#" }
                 g = "${color #00ff00}"; for(;n>0;n--)      g = g "\\#";
  print g y r
  printf "%50s"," "
 }' }
${color}

My df --output=pcent outputs 2 lines; the second one is a percentage used, eg 69%. I tried this on conky 1.9.


If your ~/.conkyrc file has been converted to format version 1.10 then it will contain a line

conky.text = [[

Make sure you add the above script before the final closing ]]. Also, in 1.10 colours given as numbers (eg #ff0000 above) no longer begin with # so you should use ff0000 and so on in the script. To simplify, put the following script into a separate file somewhere in your PATH, say ~/mydf, make it executable (chmod +x ~/mydf), and then put that filename in ~/.conkyrc, eg ${execpi 30 ~/mydf /}

#!/bin/bash
df --output=pcent "${1?}" | awk 'NR==2{
   n = ($1+0)/2; yellow = 20; red = 40;
   if(n>=red)   { r = "${color ff0000}"; for(;n>=red;n--)   r = r "\\#" }
   if(n>=yellow){ y = "${color ffff00}"; for(;n>=yellow;n--)y = y "\\#" }
                  g = "${color 00ff00}"; for(;n>0;n--)      g = g "\\#";
   print g y r
   printf "%50s"," "
  }'

If you want to put the whole script in the ~/.conkyrc file, you will need to increase the default buffer size or the command will be truncated to 256 characters. This leads to errors like

sh: -c: line 0: unexpected EOF while looking for matching `''

To do this, in 1.10 add a line inside the conky.config={...} part, making sure you separate the settings with a comma (,):

text_buffer_size = 400,

In conky 1.9 add a line before the TEXT section:

text_buffer_size 400

To stop the window resizing as the number of characters printed increases, a final printf "%50s"," " adds a second line of spaces of the maximum length. Alternatively, add a configuration setting for the minimum size of the window in pixels, eg minimum_size 500 (or minimum_size=500, for 1.10), where the value to use depends on the font width of the # character.

  • My output is an empty extra line at the end of Conky. I have added it to the end of my conf file. – xvlaze Nov 26 '16 at 20:33
  • Try running the command (from df ... to the }' in your shell. It should output something like ${color #00ff00}\#\#\#\#.... – meuh Nov 26 '16 at 20:37
  • I tried it before and seemed to work as expected. My output is ${color #00ff00}\#\#. – xvlaze Nov 26 '16 at 20:45
  • You could try adding a final $hr command at the end for a horizontal line. Or try replacing the \\# which might be troublesome, with say X. If you run conky from the terminal does it write any error messages? What version conky do you have? There were changes in 1.10. – meuh Nov 26 '16 at 20:54
  • I copypasted your snippet and my output was: $ conky conky: desktop window (9a) is root window conky: window type - desktop conky: drawing to created window (0x1400001) sh: -c: line 0: unexpected EOF while looking for matching `'' sh: -c: line 7: syntax error: unexpected end of file ^Cconky: received SIGINT or SIGTERM to terminate. bye! – xvlaze Nov 26 '16 at 21:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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