#!/bin/sh set -o errexit main() { # Redraw when the active group or the window list changes. # -spy prints once at startup too, so the bar draws immediately. xprop -root -spy _NET_CURRENT_DESKTOP _NET_CLIENT_LIST | while read -r _; do groups done | lemonbar-xft -g x18 -B '#222222' -F '#dddddd' | sh } groups() { cur=$(xprop -root _NET_CURRENT_DESKTOP | awk '{print $3}') num=$(xprop -root _NET_NUMBER_OF_DESKTOPS | awk '{print $3}') # groups that currently contain windows occ=$(for w in $(xprop -root _NET_CLIENT_LIST | cut -d'#' -f2 | tr -d ','); do xprop -id "$w" _NET_WM_DESKTOP 2>/dev/null | awk '{print $3}' done | sort -u) out="" i=1 # skip 0 ("nogroup") while [ "$i" -lt "$num" ]; do if [ "$i" -eq "$cur" ]; then out="$out%{R} $i %{R}" # active: reversed colors elif echo "$occ" | grep -qx "$i"; then out="$out%{A:xdotool set_desktop $i:} $i %{A}" # occupied, clickable else out="$out%{F#555}%{A:xdotool set_desktop $i:} $i %{A}%{F-}" # empty, dimmed fi i=$((i + 1)) done echo "%{l}$out" } main