In the $HOME/.config/i3/config set the bar section to this:
bar {
# comment this line as it is the default value
# status_command i3status
status_command /path/to/your/script.sh
}
Create the script /path/to/your/script.sh and give it execution permissions.
#!/bin/sh
echo '{ "version": 1 }'
# Begin the endless array.
echo '['
# We send an empty first array of blocks to make the loop simpler:
echo '[]'
while :;
do
hour=$(date "+%H:%M:%S")
today=$(date "+%b/%d")
ip_addr=$(nmcli | grep inet4 | awk '{print $2}')
if [ $(ip link show | grep --color=never -c "state UP") -eq 0 ];
then
ip_addr="offline"
fi
used_mem=$(free -h | grep Mem | awk '{print $3}' | sed "s/i//")
free_disk=$(df -h | egrep "\/$" | awk '{print $4}')
cpu_load=$(top -b -d1 -n1|grep -i "Cpu(s)"|head -c21|cut -d ' ' -f3|cut -d '%' -f1 | sed "s/us,/0.0/")
# comment this if you are not in a laptop and remove the corresponding JSON line
battery=$(upower -i $(upower -e | grep BAT) | grep --color=never -E "percentage" | awk '{print $2}')
JSON=$(cat <<EOF
,[{
"full_text": " π¨πΊ ", "color": "#ffffff", "separator": false, "border_right": 0, "border_left": 0, "separator_block_width": 0
},{
"full_text": "ξ²", "color": "#ea3d3d", "separator": false, "border_right": 0, "border_left": 0, "border_bottom": 4, "border_top": 0, "separator_block_width": 0, "background": "#000000"
},{
"full_text": " CPU: π½ $cpu_load ", "color": "#ffffff", "separator": false, "border_right": 0, "border_left": 0, "separator_block_width": 0, "background": "#ea3d3d"
},{
"full_text": "ξ²", "color": "#3b47aa", "separator": false, "border_right": 0, "border_left": 0, "border_bottom": 4, "border_top": 0, "separator_block_width": 0, "background": "#ea3d3d"
},{
"full_text": " Used mem: π $used_mem ", "color": "#ffffff", "separator": false, "border_right": 0, "border_left": 0, "separator_block_width": 0, "background": "#3b47aa"
},{
"full_text": "ξ²", "color": "#5f00af", "separator": false, "border_right": 0, "border_left": 0, "border_bottom": 4, "border_top": 0, "separator_block_width": 0, "background": "#3b47aa"
},{
"full_text": " Free disk: β $free_disk ", "color": "#ffffff", "separator": false, "border_right": 0, "border_left": 0, "separator_block_width": 0, "background": "#5f00af"
},{
"full_text": "ξ²", "color": "#2c7b39", "separator": false, "border_right": 0, "border_left": 0, "border_bottom": 4, "border_top": 0, "separator_block_width": 0, "background": "#5f00af"
},{
"full_text": " π» $ip_addr ", "color": "#ffffff", "background": "#2c7b39", "separator": false, "border_right": 0, "border_left": 0, "separator_block_width": 0
},{
"full_text": "ξ²", "color": "#875fd7", "separator": false, "border_right": 0, "border_left": 0, "border_bottom": 4, "border_top": 0, "separator_block_width": 0, "background": "#2c7b39"
},{
"full_text": " ποΈ $today ", "color": "#ffffff", "background": "#875fd7", "separator": false, "border_right": 0, "border_left": 0, "separator_block_width": 0
},{
"full_text": "ξ²", "color": "#5f00af", "separator": false, "border_right": 0, "border_left": 0, "border_bottom": 4, "border_top": 0, "separator_block_width": 0, "background": "#875fd7"
},{
"full_text": " π’ $hour ", "color": "#ffffff", "background": "#5f00af", "separator": false, "border_right ": 0, "border_left": 0, "separator_block_width": 0
}]
EOF
)
echo $JSON
sleep 1
done