Sagar Behere

I doubt, therefore I might be

Using conky with i3

i3 is a neat, tiling window manager. This post describes how to use conky to output a status line which is displayed in i3bar.

i3bar allows any command that generates a line of text to be used as the status_command. Therefore, we use conky to generate the desired line of text. In order to use conky to generate a line of text for i3bar, the important configuration options are

out_to_x no
own_window no
out_to_console yes
background no

my own conky configuration file is below, which produces an output similar to that produced by i3status, but with some more information. It includes CPU %load, frequency, temperature as well as percentage of RAM being used and current weather conditions. The weather information is fetched using a program called weather-util, which is available in the debian repositories.

[conkyrc] conkyrc download
### Conky configuration file
## Output is printed to the console -> i3bar
# Modified: 27.11.2011 - mseed : http://www.fastlinux.eu

### 
# use_xft yes
# xftfont Helvetica:size=15
# xftalpha 0.9

## No output to X <yes/no>
out_to_x no

## Create own window to draw <yes/no>
own_window no

## Print everything to console?
out_to_console yes

## Use double buffering (reduces flicker, not needed for console output)
double_buffer no

## Set to yes if you want Conky to be forked in the background
background no

## Update interval in seconds
update_interval 2.0

## This is the number of times Conky will update before quitting.
## Set to zero to run forever.
total_run_times 0

## Shortens units to a single character (kiB->k, GiB->G, etc.). Default is off.
short_units yes

## How strict should if_up be when testing an interface for being up?
## The value is one of up, link or address, to check for the interface
## being solely up, being up and having link or being up, having link
## and an assigned IP address. 
if_up_strictness address

## Add spaces to keep things from moving about?  This only affects certain objects.
## use_spacer should have an argument of left, right, or none
use_spacer left

## Force UTF8? note that UTF8 support required XFT
override_utf8_locale no

## number of cpu samples to average
## set to 1 to disable averaging
cpu_avg_samples 2

## Sensors examples
# Top Process: ${top name 1}
# Root: {fs_used /}/${fs_size /} /home ${fs_free /home} /${fs_size /home}
# Load: ${loadavg 1} ${loadavg 2} ${loadavg 3} 
# Load: $loadavg
# Swap: ${swap}/${swapmax} (${swapperc}%)
# Processes: ${running_processes} / ${processes}
# CPU: $cpu% 
# HDD: $diskio_read :Read $diskio_write :Write
# Temp: Core0: ${exec sensors | awk '/Core 0/ {print $3}'} Core1: ${exec sensors | awk '/Core 1/ {print $3}'}
# Freq: ${freq cpu0}Mhz
# Uptime: $uptime
# Kernel:$kernel on $machine
# Name: $nodename - $sysname
# Battery: ${battery_percent BAT0}%

## Stuff after 'TEXT' will be formatted on screen
TEXT
# Free space on /home
/home ${fs_free /home} | \
# Ethernet status
${if_up eth0}eth0 ${addr eth0} | ${endif}\
# Wireless status
${if_up wlan0}wlan0 ${addr wlan0} | ${endif}\
# CPU stats
CPU ${cpu cpu1}% ${freq_g 1}GHz ${exec sensors | grep -m 1 "Core 0"|awk '{print $3}'} | \
# RAM in use
RAM ${memperc}% | \
#BATT ${battery BAT0} | \

${time %a %d.%m.%y} ${time %H:%M} | \
# Weather temperature
${exec weather --headers="Temperature" -q | awk '/Temperature/ {print $2}'}C ${exec weather --headers="Sky conditions" -q | awk '/Sky conditions/ {print $3 " " $4}'} | \
# Volume %
#Vol: ${mixer}
V ${exec pactl list sinks | grep "Volume: 0"| tail -n 1 | awk '{print substr($3, 1, index($3, "%") - 1)}'}%

you can test the conky output with the command

conky -c /path/to/conkyrc

and it should show the line of status text. Next, set i3 bar to display this text by modifying the status_command line in the i3bar section of your i3 config file (which is usually $HOME/.i3/config). For example, the relevant part of my .i3/config is

# Start i3bar to display a workspace bar (plus the system information i3status
# finds out, if available)
bar {
    colors {
        # Show status text in light blue color
            statusline #ADD8E6
    }
        status_command conky -c ~/.conkyrc
        position top
}

This gives a status bar similar to the picture below

If you prefer to have pretty icons for the information, instead of text like "CPU" or "RAM", there are two possibilities. The first possibility (which is rather hacker-ish) is to use unicode symbols as icons. Of course, you should make sure that the font being used by i3 supports the unicode symbols you are using. The other option is to use special fonts (.ttf or .otf) which are made especially for being used as icons. An example font is the Weather font. Conky can use these fonts and then the text output by conky will contain the icon symbols, but the symbols will still be "text" since they are part of a font. This latter approach requires using the latest version of i3 (the git "next" version, as of this writing, which is 4.2.1-0+g4.2-298-gcfa74c51) obtained from the i3 debian repository. This because the latest version supports Xft fonts in addition to X core fonts.

You can use an Xft font in the latest version of i3 by including a line like the following in you your .i3/config file

font xft:Monospace 12

see the i3 user guide for more details.