6 <div id="content" class="usergen">
7 <h1>User-contributed article: Using conky with i3bar</h1>
10 As explained in the i3 documentation, it’s possible to <a
11 href="http://i3wm.org/docs/userguide.html#_displaying_a_status_line">use an
12 external program to build the status information displayed
14 One of those programs is <a href="http://conky.sourceforge.net/">conky, a free,
15 light-weight system monitor</a>.
19 Since conky does not support the i3bar protocol by default, we could use the
20 plain text output format, but then we cannot have i3bar display colors. This
21 article shows how to configure conky to have colors with i3bar.
25 As explained in more detail in the <a
26 href="http://i3wm.org/docs/i3bar-protocol.html">i3bar protocol description</a>,
27 i3bar can receive input serialized as JSON, and this way has color support,
28 among other things (urgency flag, shortening description if more space is needed).
31 <h2>Example of colored status with conky</h2>
34 First of all we have to understand how i3bar expects JSON input:
35 We have to provide an "infinite array", each element on that array is a "status
36 line" that is displayed at a certain moment by i3bar.
40 Let's make a short example.
41 We want to build a very simple status that displays the amunt of free space in
42 home folder and the percentage of used RAM.
43 Here's a sample JSON text for achieving our goal:
46 <pre><tt>{"version":1}
50 [ { "full_text":"Home 84.0G Free", "color":"#ffffff" },
51 { "full_text":"RAM 32%" , "color":"#ffffff" } ],
53 [ { "full_text":"Home 84.0G Free", "color":"#ffffff" },
54 { "full_text":"RAM 34%" , "color":"#ffffff" } ],
61 The first line tells i3bar that we are using JSON input.
62 The second line is the opening of the "infinite array".
63 Each line after second is one "instance status" to be displayed in i3bar,
66 <h2>Wrapper script</h2>
69 To obtain this output with conky we have to use it in combination with a short script.
70 The script will write down the "fixed" part of the output (first and second line), then it will call conky.
71 It will be conky’s duty to write each of the "instances".
75 The script is quite simple:
80 # Send the header so that i3bar knows we want to use JSON:
83 # Begin the endless array.
86 # We send an empty first array of blocks to make the loop simpler:
89 # Now send blocks with information forever:
90 exec conky -c $HOME/.conkyrc</tt></pre>
93 Let's save this script as <tt>conky-i3bar</tt> in <tt>$HOME/bin</tt>.
94 In the i3 config file the <tt>bar</tt> config will be something like that
98 status_command $HOME/bin/conky-i3bar
101 <h2>conky configuration</h2>
104 Now we have to write a <tt>~/.conkyrc</tt> file in order to obtain the desired status:
107 <pre><tt>[{ "full_text":"Home 84.0G Free" , "color":"#ffffff" },
108 { "full_text":"RAM 32%" , "color":"#ffffff" }],</tt></pre>
111 Here's a sample conkyrc that updates every 2 seconds. Just to make things a litte bit more exciting
112 we put a condition in the script in order to write the occupied RAM in red if the amount is more than 90%:
115 <pre><tt>conky.config = {
118 out_to_console = true,
122 -- Update interval in seconds
123 update_interval = 2.0,
125 -- This is the number of times Conky will update before quitting.
126 -- Set to zero to run forever.
129 -- Shortens units to a single character (kiB->k, GiB->G, etc.). Default is off.
132 -- How strict should if_up be when testing an interface for being up?
133 -- The value is one of up, link or address, to check for the interface
134 -- being solely up, being up and having link or being up, having link
135 -- and an assigned IP address.
136 if_up_strictness = 'address',
138 -- Add spaces to keep things from moving about? This only affects certain objects.
139 -- use_spacer should have an argument of left, right, or none
142 -- Force UTF8? note that UTF8 support required XFT
143 override_utf8_locale = false,
145 -- number of cpu samples to average
146 -- set to 1 to disable averaging
149 -- Stuff after 'TEXT' will be formatted on screen
154 [{ "full_text" : "Home ${fs_free /home} Free" , "color" : "\#ffffff" },
155 { "full_text" : "RAM ${memperc}%" , "color" :
156 ${if_match ${memperc}<90}"\#ffffff"${else}"\#ff0000"${endif} }],