Skip to content

Instantly share code, notes, and snippets.

@olmokramer
Last active August 8, 2023 18:18
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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
@finex
Copy link

finex commented Nov 5, 2020

Hi, is it possible to change the tag by clicking on this module? I've read some docs but it looks that this implementation doesn't allow to interact with. Thanks for your feedback :-)

@olmokramer
Copy link
Author

Hi, yes it is possible to make them clickable. See the Polybar wiki's section on formatting on how to do so. Basically just wrap each tag name in ${A1:herbstclient use $name:}.

@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