Skip to content

Instantly share code, notes, and snippets.

@olmokramer
Last active August 8, 2023 18:18
Show Gist options
  • Save olmokramer/b28ff8ed5fd366e3ebb23b79915ec850 to your computer and use it in GitHub Desktop.
Save olmokramer/b28ff8ed5fd366e3ebb23b79915ec850 to your computer and use it in GitHub Desktop.
Herbstluftwm workspaces for polybar
[module/herbstluftwm]
type = custom/script
exec-if = ps -C herbstluftwm >/dev/null 2>&1
exec = MONITOR=HDMI-0 ~/.config/polybar/herbstluftwm.sh
tail = true
#!/bin/sh
hash herbstclient xrandr
print_tags() {
for tag in $(herbstclient tag_status "$1"); do
name=${tag#?}
state=${tag%$name}
case "$state" in
'#')
printf '%%{R} %s %%{R}' "$name"
;;
'+')
printf '%%{F#cccccc}%%{R} %s %%{R}%%{F-}' "$name"
;;
'!')
printf '%%{R} %s! %%{R}' "$name"
;;
'.')
printf '%%{F#cccccc} %s %%{F-}' "$name"
;;
*)
printf ' %s ' "$name"
esac
done
printf '\n'
}
geom_regex='[[:digit:]]\+x[[:digit:]]\++[[:digit:]]\++[[:digit:]]\+'
geom=$(xrandr --query | grep "^$MONITOR" | grep -o "$geom_regex")
monitor=$(herbstclient list_monitors | grep "$geom" | cut -d: -f1)
print_tags "$monitor"
IFS="$(printf '\t')" herbstclient --idle | while read -r hook args; do
case "$hook" in
tag*)
print_tags "$monitor"
;;
esac
done
@timjstewart
Copy link

This worked for me "%{A1:herbstclient use $name:}$name %{A}".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment