Preface

I’m so excited with the release of Conky V1.10. The latest conky configuration is actualy a Lua file. It is very flexible, compared with the old plain text Conky Configuration. We can separate the long old conky TEXT, into separate Lua function.

One application benefit from this Conky Lua Config is i3status. Before we get too deep, let’s see the old way of configuring i3status with Conky.

Table of Content


Screenshot

Screenshot Information
OS: Arch
WM: i3-gaps

+ Statusbar: i3bar

+ Rofi

+ Terminal: Termite
- ViM: NERDTree
- perl-term-extendedcolor
- ls++

i3-gaps: Conky Lua in dark i3status


1: The i3 config

I assume that you have already familiar with i3 config.

Reading:

The only thing you need to concern is the bar section. We will change the status_command few times.

bar {

# default i3 status config
    status_command i3status
    
    position       bottom  
    
    colors {
        background #000000
        statusline #c9c925
        separator  #ffffff
              
        # class            border    backgrd   text
        focused_workspace  #161616   #c9c925   #000000
        active_workspace   #161616   #5c5dad   #a5a5a5
        inactive_workspace #161616   #222222   #5c5dad
        urgent_workspace   #161616   #ad3737   #ffffff
    }
}

i3status: workspace

You can check my dotfiles here

I put two configs, one the original i3-wm, and the other for i3-gaps. Just copy one of them to ~/.config/i3/config

$ cat ~/.config/i3/config

There are others i3 variant, e.g sway for wayland, and i3bgbar with powerline looks (deprecated). I haven’t explore the configuration yet.

In order to see change, each time changing status_command, you must restart i3 with Mod+Shift+r or utilizing command line.

$ i3-msg restart

2: Using i3bar

AFAIK there are three kind of configuration that can be used as a feed to i3bar.

i3status

Let’s copy the default i3status configuration.

$ mkdir ~/.config/i3/i3status
$ cp /etc/i3status.conf ~/.config/i3/i3status/default.conf

And make your own customization.

bar {
    status_command i3status --config ~/.config/i3/i3status/custom.conf
    }

i3status

i3blocks

Let’s copy the default i3blocks configuration.

$ mkdir ~/.config/i3/i3blocks
$ cp /etc/i3blocks.conf ~/.config/i3/i3blocks/default.conf

And make your own customization.

bar {
   status_command i3blocks -c ~/.config/i3/i3blocks/custom.conf
    }

i3blocks

Conky

Example

bar {
     status_command conky -c ~/.config/i3/conkyrc
    }

We can have many i3bar in i3wm. Each configured in different bar section.


3: Plain Conky

This is how we do conky in a very simple way, before Conky v.1.10, and without JSON.

bar {
     status_command conky -c ~/.config/i3/conky/01.old/conkyrc
    }

And this is the conkyrc file

out_to_x no
out_to_console yes
update_interval 1

TEXT
${if_mpd_playing}♫  ${mpd_artist} -  ${mpd_title} | ${endif}\
${time %H:%M:%S}    

Conky: old


Conky Config as Lua

Just like what I said before, the latest Conky v1.10 configuration is actually a Lua file.

bar {
     status_command conky -c ~/.config/i3/conky/02.lua/conkyrc.lua
    }

And you see the difference in this conkyrc.lua file.

conky.config = {
    background = false,
    out_to_x = false,
    out_to_console = true,
    update_interval = 1,
    total_run_times = 0,
    use_spacer = "none"
}

conky.text = [[ 
${if_mpd_playing}♫  ${mpd_artist} -  ${mpd_title} | ${endif}\
${time %H:%M:%S}    
]]

Conky: lua

Reading:


4: Conky as JSON Feed

Once again, we have to change the status_command. This time we are using a shell script to start json header. And this script will call conky.

bar {
    status_command ~/.config/i3/conky/03.json/json.sh
    }

The conkyrc.lua started to look a bit complicated right now. The conky.config part is the same as above. But the conky.text is very different to accomodate i3bar JSON protocol.

conky.text = [[ 
[ 
# MPD
${if_mpd_playing} 
    {"full_text":"", "color":"\#c9c925", 
     "separator":false, "separator_block_width":6},
    {"full_text":"${mpd_artist 20}", "color" : "\#5c5dad", 
     "separator" : false, "separator_block_width":3 },
    {"full_text":" - ", "color" : "\#909737", 
     "separator" : false, "separator_block_width":3 },
    {"full_text":"${mpd_title 30}", "color" : "\#545454", 
     "separator" : false, "separator_block_width":6 },
${else} 
    {"full_text":"", "color":"\#c92525",
     "separator" : false, "separator_block_width":6 },
${endif}

# Time:
    {"full_text":"|", "color":"\#545454", 
     "separator":false, "separator_block_width":6},
    {"full_text":"", "color":"\#c9c925", 
     "separator":false, "separator_block_width":6},
    {"full_text":"TIME", "color":"\#5c5dad", 
     "separator":false,"separator_block_width":6},
    {"full_text":"${time %H:%M }", "color":"\#aaaaaa", 
     "separator":false, "separator_block_width":6 }
],
]]

Conky: JSON

This script is only using two monitoring widgets, it is mpd and time. For many monitoring widget, we should reduce the complexity.

Reading


5: Modular

You can make your own modular script for your own needs. This just a sample.

The i3 config

Mine using two bars. Top and Bottom.

bar {
    status_command ~/.config/i3/conky/04.modular/json.top.sh
    position       top
    workspace_buttons      no
}

bar {
    status_command ~/.config/i3/conky/04.modular/json.bottom.sh
    position       bottom  
}

The Lua Helper

Since we want to reduce complexity, we create a function for each json parts in jsonhelper.lua.

-- global
jsonhelper = {}

function jsonhelper.text(text, color)
  color = color or #5c5dad

  return [[  {
    "full_text":"]] .. text .. [[",
    "color":"\]] .. color .. [[",
    "separator":false,
    "separator_block_width":6}
  ]]
end

I provide few functions

  • jsonhelper.separator()
  • jsonhelper.icon()
  • jsonhelper.text()
  • jsonhelper.value()
  • jsonhelper.common()

The last one is just a call to all other function at once [separator, icon, text, value]. So we call them in just one line.

parts.time = jsonhelper.common('', nil, '${time %H:%M }')
parts.mem  = jsonhelper.common('', 'RAM', '$mem/$memmax')

The dollar $ syntax indicate conky variables.

You can check the rest of the file in github

If you need more icon you can copy-paste from FontAwesome cheatsheet, but be aware that it is not always work with other font.

The Parts Lua

Now we need another file to define conky parts as functions.

parts = {}

-- user variables
local wlandev = 'wlan0'

-- shortcut
local _h = jsonhelper

-- Media Player Daemon
parts.mpd = [[
${if_mpd_playing} 
]] .. _h.icon('') .. [[,
    {"full_text":"${mpd_artist 20}", "color" : "\#5c5dad", 
     "separator" : false, "separator_block_width":3 },
    {"full_text":" - ", "color" : "\#909737", 
     "separator" : false, "separator_block_width":3 },
    {"full_text":"${mpd_title 30}", "color" : "\#545454", 
     "separator" : false, "separator_block_width":6 }
${else} 
    {"full_text":"", "color":"\#c92525", 
     "separator" : false, "separator_block_width":6 }
${endif} 
]]

You can check the rest of the file in github

Main Conkyrc Script

Now we can call this script in conky.text in main conkyrc.lua file.

conky.text = [[ 
[ 
]] .. parts.date .. [[, 
]] .. parts.time .. [[ 
],
]]

You can check the rest of the file in github


6: Miscellanous

Changing Color

This is a bonus parts. For your convenience I put two colorschemes. It is for dark and bright wallpaper. Of course you can add your own colorscheme.

local color_preset_dark = {
  icon      = '#c9c925',
  text      = '#5c5dad',
  separator = '#545454',
  value     = '#aaaaaa'
}

local color_preset_bright = {
  icon      = '#5c5dad',
  text      = '#606040',
  separator = '#c9c925',
  value     = '#000000'
}

local color_preset = color_preset_bright

i3-gaps: Conky Lua in bright i3status

Font Problem

Do not forget to install font to enable your icons.

$ sudo pacman -S ttf-font-icons
$ yaourt -S awesome-terminal-fonts

Conclusion

After all this is just a config. You may modify this config to suit your needs.