Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Feeds i3bar with current Qubes system status
# By @minad and @SietsevanderMolen
json() {
if [[ -n "$3" ]]; then
echo -n "{\"name\":\"$1\",\"color\":\"$3\",\"full_text\":\"$2\"},"
echo -n "{\"name\":\"$1\",\"full_text\":\"$2\"},"
status_net() {
local net=$(qvm-run $WIFI_VM -p 'iwconfig; ifconfig' 2>/dev/null)
local ssid=$(echo "$net" | perl -ne 'print $1 if /ESSID:"(.*)"/')
if [[ -n $ssid ]]; then
local quality=$(echo "$net" | perl -ne 'print "$1 " if /Quality=([^ ]+)/')
json wifi "W: $quality$ssid"
local ip=$(echo "$net" | perl -ne 'if (/^[w|e]/../^$/) { print $1 if /inet ([^ ]+)/ }')
[[ -n $ip ]] && json ip "I: $ip"
status_time() {
local time=$(date '+%F %T')
echo -n "{\"name\":\"time\",\"full_text\":\"$time\"}" # last entry
status_bat() {
local bat_now=$(cat /sys/class/power_supply/BAT0/energy_now 2>/dev/null)
local bat_full=$(cat /sys/class/power_supply/BAT0/energy_full_design 2>/dev/null)
if [[ -n "$bat_full" ]]; then
local bat=$((100*bat_now/bat_full))
local ac=''
local color='#00ff00'
if [[ $(cat /sys/class/power_supply/AC/online) == '1' ]]; then
ac=' AC'
elif ((bat < 25)); then
elif ((bat < 50)); then
json bat "B: $bat%$ac" "$color"
status_load() {
local load=$(uptime)
load=${load/#*load average: }
json load "$load"
status_qubes() {
local qubes=$(qvm-ls 2>/dev/null | grep ' \* ' | wc -l)
json qubes "$qubes Q"
status_disk() {
local disk=`df -h / | tail -n 1 | awk '{print $4}'`
json disk "D: $disk"
main() {
echo '{"version":1}'
echo '['
echo '[]'
local n
for ((n=0; ; ++n)); do
if (( n % 10 == 0 )); then
local qubes=$(status_qubes)
local net=$(status_net)
local disk=$(status_disk)
local bat=$(status_bat)
local load=$(status_load)
local time=$(status_time)
echo ",[$qubes$net$disk$bat$load$time]"
sleep 1

This comment has been minimized.

Copy link

one7two99 commented Oct 3, 2017

Hello, can you add some more information what the changes are for you've made at the status_net part ?
Maybe also interesting for you:
I've also switched to i3wm and added my /usr/bin/qubes-i3status to get additional battery runtime information like the current discharge rate, to monitor VM usage and battery impact:

status_bat() {
local my_bat=/sys/class/power_supply/BAT0
# calculate current battery discharge rate (hint: could be adapted for AC)
local bat_rate=$(bc <<< "scale=1;cat $my_bat/current_nowcat $my_bat/voltage_now/10^12")"W"
# calculate how empty/full your battery is
local bat=$((100
cat $my_bat/charge_now/cat $my_bat/charge_full_design))
local ac=''
local color=''
if [[ $(cat /sys/class/power_supply/AC/online) == '1' ]]; then
ac=' AC'
elif ((bat < 25)); then
color='#ff0000' # red
elif ((bat < 50)); then
color='#ff6600' # orange
json bat "Bat: $bat_rate $bat%$ac" "$color"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.