<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>i3 FAQ - Individual question feed</title><link>https://faq.i3wm.org/questions/</link><description>Frequently asked questions and answers about the i3 window manager</description><atom:link href="http://faq.i3wm.org/feeds/question/3894/" rel="self"></atom:link><language>en</language><copyright>Copyright i3, 2012</copyright><lastBuildDate>Sun, 01 Jun 2014 16:48:39 +0000</lastBuildDate><item><title>How to customise the i3bar?</title><link>https://faq.i3wm.org/question/3894/how-to-customise-the-i3bar/</link><description>My question is quite straight forward, how to customise the i3bar and add the information I want. 

How I can do that?</description><pubDate>Fri, 30 May 2014 13:31:31 +0000</pubDate><guid>https://faq.i3wm.org/question/3894/how-to-customise-the-i3bar/</guid></item><item><title>Answer by phairland for &lt;p&gt;My question is quite straight forward, how to customise the i3bar and add the information I want. &lt;/p&gt;

&lt;p&gt;How I can do that?&lt;/p&gt;
 </title><link>https://faq.i3wm.org/question/3894/how-to-customise-the-i3bar/?answer=3895#post-id-3895</link><description>You can actually use any programming language or command that outputs data.  For example my i3bar consists of weather, bitcoin exchange rate, cpu load, temp, battery, dropbox status, wifi status, volume, date and time. All these I got by using `tcl` to call commands and format the output with `sed`, `awk`, `grep` and `cut`.

The file output a JSON format that i3bar can understand, so basically you can use any programming language or program that outputs data and format it according to the i3 JSON guidelines.

Besides my program outputting all that data onto the i3bar, it will change color according to the status. For example, temp is green when is less than 65, yellow when is between 65 and 74 and red when is more than 74. Wifi and Dropbox are red when offline, and cpu load follows the same pattern. Another is the charge when laptop on batteries, it will turn red when less tha 20%. 

Then you can add almost anything including things you can find on the web, like weather and exchange rates. Most programming languages have http apis that provides you with tools to extract information from webpages, and that's why the i3bar is so powerful. 

Tcl code is quite straight forward and you can look at the code and modify it in your programming language of choice and since most of the formatting is done using external programs like `sed` and `awk`. The only thing you need to be wary of is how tcl handles awk code, for example when in tcl code `awk {{print $3}}` in other programming languages and awk itself is `awk '{print $3}'` as there is special case how tcl handles single quotes, so it have to use curly braces instead.

On the i3.conf I got the following line to call my tcl file:

    bar {
    position top
    status_command i3status --config ~/.config/i3/i3status.conf | ~/.config/i3/status.tcl
    colors {
    urgent_workspace   #000000 #000000 #c0c0c0
    }
    }

Then my `status.tcl` file:

    #!/bin/tclsh
    package require http
    ::http::config -useragent "Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Firefox/24.0"
    set    red "#FF0000"
    set  green "#00FF00"
    set yellow "#FFF000"
    set   blue "#00EAFF" 
    set  white "#FFFFFF" 
    puts {{"version":1}
    [
    []}
    proc dropbox {} {
        catch { exec dropbox status} msg 
        set dropbox $msg
        if {$dropbox=="Dropbox isn't running!" || [string match Connecting* $dropbox]} {
            set stdout {{"name":"dropbox","full_text":"IDLE","color": "$::red"}}
        } else {
            set dropbox [string toupper $dropbox 0 end]
            regsub -all {\.\.\.} $dropbox " " dropbox 
            set dropbox [split $dropbox " "]
            set dropbox [lindex $dropbox 0] 
            set dropbox [string range $dropbox 0 3]
            if {$dropbox=="UP"} {set dropbox "IDLE"}
            set stdout {{"name":"dropbox","full_text":"$dropbox","color": "$::green"}}
        }
        set stdout [subst -nocommands $stdout]
        puts -nonewline $stdout
    }
    proc wifi {} {
        set hostname [exec hostname]
        if {$hostname=="R730"} {set con "wlp2s0"} else {set con "wlp3s0"}
        set wifi [exec iwconfig $con | sed -ne /Point/p | awk {{print $6}}]
        if {[string match *Not-Associated* $wifi] } {
            set stdout {{"name":"wifi","full_text":"WIFI","color": "$::red"}} 
        } else { 
            set stdout {{"name":"wifi","full_text":"WIFI","color": "$::green"}}
        }
        set stdout [subst -nocommands $stdout]
        puts -nonewline $stdout
    }
    proc hour {} {
        set hour [clock format [clock sec] -format %H:%M] 
        set stdout {{"name":"hour","full_text":"$hour"}} 
        set stdout [subst -nocommands $stdout]
        puts -nonewline $stdout
    }
    proc date {} {
        set date [clock format [clock sec] -format {%a}]
        set date [string toupper $date]
        set date_number [clock format [clock sec] -format {%e}]
        set suffix [en_ordinal $date_number]
        if {[string range $date_number 0 0]!=" "} {set date "$date "}
        set stdout {{"name":"date","full_text":"$date$suffix","color": "$::white"}} 
        set stdout [subst -nocommands $stdout]
        puts -nonewline $stdout
    }
    proc en_ordinal n {
        set suffix th
        if {($n%100)&lt;10 || ($n%100)&gt;20} {
            switch -- [expr abs($n)%10] {
                1 {set suffix st}
                2 {set suffix nd}
                3 {set suffix rd}
            }
        }
        append n $suffix
    } 
    proc battery {} {
        set battery [exec acpi]
        set percentage [exec acpi | awk {{print $4}} | sed {s/%,//}]
        if {[string match *Discharging* $battery]} {
        if {$percentage &gt;= 20} {set color "$::yellow"}
        if {$percentage &lt;  20} {set color "$::red"}
        regsub -all "," $battery "" battery 
        set charge [lindex $battery 3]
        set remain [lindex $battery 4]
        set stdout {{"name":"battery","full_text":"$charge $remain","color": "$color"}} 
       } else { set stdout {{"name":"battery","full_text":"D=","color": "$::green"}} 
    }
        set stdout [subst -nocommands $stdout]
        puts -nonewline $stdout
    }
    proc volume {} {
        set vol [exec amixer sget Master | awk {-F[][]} {/dB/ { print $2 }} | head -1]
        regsub -all "%" $vol "♬" vol 
        set stdout {{"name":"volume","full_text":"$vol","color":"$::blue"}} 
        set stdout [subst -nocommands $stdout]
        puts -nonewline $stdout
    }
    proc cpu_load {} {
        set cpu_load [exec sar 1 1 | sed -n {4p} | awk {{print $8}}]
        set cpu_load [expr 100-$cpu_load]
        set cpu_load [format "%.2f" $cpu_load]
        if {$cpu_load &lt;= 59.99} {set color "$::green"}
        if {$cpu_load &gt;= 60 &amp;&amp; $cpu_load &lt;= 79.99} {set color "$::yellow"}
        if {$cpu_load &gt;= 80} {set color "$::red"}
     set stdout {{"name":"cpu_load","full_text":"$cpu_load","color":"$color"}} 
        set stdout [subst -nocommands $stdout]
        puts -nonewline $stdout
    }
    proc cpu_temp {} {
        set cpu_temp [exec sensors | grep Core | sed -n  {2p} | awk {{print $3}} | cut -c2-3]
        if {$cpu_temp &lt;= 64} {set color "$::green"}
        if {$cpu_temp &gt;= 65 &amp;&amp; $cpu_temp &lt;= 74} {set color "$::yellow"}
        if {$cpu_temp &gt;= 75} {set color "$::red"}
        set stdout {{"name":"cpu_temp","full_text":"$cpu_temp°C","color":"$color"}} 
        set stdout [subst -nocommands $stdout]
        puts -nonewline $stdout
    }
    set ::backup ""
    proc weather {} {
        set weather [exec tclsh /home/alber/.config/i3/weather.tcl]
        if {$weather==""} {set weather $::backup}
        set ::backup $weather
        set stdout {{"name":"weather","full_text":"$weather","color":"$::white"}} 
        set stdout [subst -nocommands $stdout]
        puts -nonewline $stdout
    }
    
    proc bitcoin {} {
        set url http://bcchanger.com/bitcoin_price_feed.php?feed_type=text&amp;currency=GBP
        if [catch { set http [::http::geturl $url] } msg] { set bitcoin ""} else {
        set bitcoin [::http::data $http] }
        regsub -all {\n} $bitcoin "" bitcoin 
        set stdout {{"name":"bitcoin","full_text":"$bitcoin","color":"$::white"}} 
        set stdout [subst -nocommands $stdout]
        puts -nonewline $stdout
    }
    while 1 {
        set begin ",\["
        set end "]"
                  puts -nonewline $begin
        weather;  puts -nonewline ","
        bitcoin;  puts -nonewline ","
        cpu_load; puts -nonewline ","
        cpu_temp; puts -nonewline ","
        battery;  puts -nonewline ","
        dropbox;  puts -nonewline ","
        wifi;     puts -nonewline ","
        volume;   puts -nonewline ","
        date;     puts -nonewline ","
        hour;     puts $end
    after 1000
    }

</description><pubDate>Fri, 30 May 2014 13:33:59 +0000</pubDate><guid>https://faq.i3wm.org/question/3894/how-to-customise-the-i3bar/?answer=3895#post-id-3895</guid></item><item><title>Answer by Man from Mars for &lt;p&gt;My question is quite straight forward, how to customise the i3bar and add the information I want. &lt;/p&gt;

&lt;p&gt;How I can do that?&lt;/p&gt;
 </title><link>https://faq.i3wm.org/question/3894/how-to-customise-the-i3bar/?answer=3901#post-id-3901</link><description>Count this as an upvote :-)</description><pubDate>Sun, 01 Jun 2014 14:59:21 +0000</pubDate><guid>https://faq.i3wm.org/question/3894/how-to-customise-the-i3bar/?answer=3901#post-id-3901</guid></item><item><title>Comment by marilion for &lt;p&gt;Count this as an upvote :-)&lt;/p&gt;
</title><link>https://faq.i3wm.org/question/3894/how-to-customise-the-i3bar/?comment=3902#comment-3902</link><description>Now you can ;-)</description><pubDate>Sun, 01 Jun 2014 16:48:39 +0000</pubDate><guid>https://faq.i3wm.org/question/3894/how-to-customise-the-i3bar/?comment=3902#comment-3902</guid></item></channel></rss>