]> git.sur5r.net Git - i3/i3.github.io/blob - docs/user-contributed/conky-i3bar.html.mako
7bccc90575ed6a527a76e1a520c3439312f4515c
[i3/i3.github.io] / docs / user-contributed / conky-i3bar.html.mako
1 <%!
2         section = "docs"
3 %>
4 <%inherit file="_templates/i3.mako" />
5 <div id="content" class="usergen">
6 <h1>User-contributed article: Using conky with i3bar</h1>
7
8 <p>
9 As explained in the i3 documentation, it’s possible to <a
10 href="http://i3wm.org/docs/userguide.html#_displaying_a_status_line">use an
11 external program to build the status information displayed
12 by i3bar</a>.
13 One of those programs is <a href="http://conky.sourceforge.net/">conky, a free,
14 light-weight system monitor</a>.
15 </p>
16
17 <p>
18 Since conky does not support the i3bar protocol by default, we could use the
19 plain text output format, but then we cannot have i3bar display colors. This
20 article shows how to configure conky to have colors with i3bar.
21 </p>
22
23 <p>
24 As explained in more detail in the <a
25 href="http://i3wm.org/docs/i3bar-protocol.html">i3bar protocol description</a>,
26 i3bar can receive input serialized as JSON, and this way has color support,
27 among other things (urgency flag, shortening description if more space is needed).
28 </p>
29
30 <h2>Example of colored status with conky</h2>
31
32 <p>
33 First of all we have to understand how i3bar expects JSON input:
34 We have to provide an "infinite array", each element on that array is a "status
35 line" that is displayed at a certain moment by i3bar.
36 </p>
37
38 <p>
39 Let's make a short example. 
40 We want to build a very simple status that displays the amunt of free space in
41 home folder and the percentage of used RAM.
42 Here's a sample JSON text for achieving our goal:
43 </p>
44
45 <pre><tt>{"version":1}
46 [
47  [].
48
49  [ { "full_text":"Home 84.0G Free", "color":"#ffffff" },
50    { "full_text":"RAM 32%" , "color":"#ffffff" } ],
51
52  [ { "full_text":"Home 84.0G Free", "color":"#ffffff" },
53    { "full_text":"RAM 34%" , "color":"#ffffff" } ],
54
55  [....],
56  [....],
57  ...</tt></pre>
58
59 <p>
60 The first line tells i3bar that we are using JSON input.
61 The second line is the opening of the "infinite array".
62 Each line after second is one "instance status" to be displayed in i3bar, 
63 </p>
64
65 <h2>Wrapper script</h2>
66
67 <p>
68 To obtain this output with conky we have to use it in combination with a short script.
69 The script will write down the "fixed" part of the output (first and second line), then it will call conky.
70 It will be conky’s duty to write each of the "instances".
71 </p>
72
73 <p>
74 The script is quite simple:
75 </p>
76
77 <pre><tt>#!/bin/sh
78
79 # Send the header so that i3bar knows we want to use JSON:
80 echo '{"version":1}'
81
82 # Begin the endless array.
83 echo '['
84
85 # We send an empty first array of blocks to make the loop simpler:
86 echo '[],'
87
88 # Now send blocks with information forever:
89 exec conky -c $HOME/.conkyrc</tt></pre>
90
91 <p>
92 Let's save this script as <tt>conky-i3bar</tt> in <tt>$HOME/bin</tt>.
93 In the i3 config file the <tt>bar</tt> config will be something like that
94 </p>
95
96 <pre><tt>bar {
97     status_command $HOME/bin/conky-i3bar
98 }</tt></pre>
99
100 <h2>conky configuration</h2>
101
102 <p>
103 Now we have to write a <tt>~/.conkyrc</tt> file in order to obtain the desired status:
104 </p>
105
106 <pre><tt>[{ "full_text":"Home 84.0G Free" , "color":"#ffffff" },
107  { "full_text":"RAM 32%" , "color":"#ffffff" }],</tt></pre>
108
109 <p>
110 Here's a sample conkyrc that updates every 2 seconds. Just to make things a litte bit more exciting 
111 we put a condition in the script in order to write the occupied RAM in red if the amount is more than 90%:
112 </p>
113
114 <pre><tt>out_to_x no
115 own_window no
116 out_to_console yes
117 background no
118 max_text_width 0
119
120 # Update interval in seconds
121 update_interval 2.0
122
123 # This is the number of times Conky will update before quitting.
124 # Set to zero to run forever.
125 total_run_times 0
126
127 # Shortens units to a single character (kiB->k, GiB->G, etc.). Default is off.
128 short_units yes
129
130 # How strict should if_up be when testing an interface for being up?
131 # The value is one of up, link or address, to check for the interface
132 # being solely up, being up and having link or being up, having link
133 # and an assigned IP address. 
134 if_up_strictness address
135
136 # Add spaces to keep things from moving about?  This only affects certain objects.
137 # use_spacer should have an argument of left, right, or none
138 use_spacer left
139
140 # Force UTF8? note that UTF8 support required XFT
141 override_utf8_locale no
142
143 # number of cpu samples to average
144 # set to 1 to disable averaging
145 cpu_avg_samples 2
146
147 # Stuff after 'TEXT' will be formatted on screen
148 TEXT
149
150 # JSON for i3bar
151 <%text filter="h">
152  [{ "full_text" : "Home ${fs_free /home} Free" , "color" : "\#ffffff" },
153   { "full_text" : "RAM ${memperc}%" , "color" :
154     ${if_match ${memperc}<90}"\#ffffff"${else}"\#ff0000"${endif} }],
155 </%text>
156 </tt></pre>