The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
1

How to customise the i3bar?

asked 2014-05-30 13:31:31 +0000

marilion gravatar image

updated 2014-05-30 13:31:51 +0000

My question is quite straight forward, how to customise the i3bar and add the information I want.

How I can do that?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
4

answered 2014-05-30 13:33:59 +0000

phairland gravatar image

updated 2014-05-31 09:29:09 +0000

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 ...
(more)
edit flag offensive delete link more
0

answered 2014-06-01 14:59:21 +0000

Man from Mars gravatar image

Count this as an upvote :-)

edit flag offensive delete link more

Comments

1

Now you can ;-)

marilion gravatar imagemarilion ( 2014-06-01 16:48:39 +0000 )edit

Question Tools

Stats

Asked: 2014-05-30 13:31:31 +0000

Seen: 1,747 times

Last updated: Jun 01 '14