#!/bin/bash # set vars tags="$1" # all, busy case $2 in +|next) dir="+";; -|prev) dir="-";; esac lobound=1; # first tag hibound=9; # last tag tagstat=$(herbstclient tag_status) function checkbusy() { case "$tagstat" in *':'$next*) busy=1;; *) busy=2;; esac } function checkbound() { if [ $next -gt $hibound ]; then next=$lobound; fi if [ $next -lt $lobound ]; then next=$hibound; fi } # get current tag for t in {1..9}; do case "$tagstat" in *"#$t"*) curtag=$t;; esac done case $tags in "busy") # only switch to busy tags if [[ "$tagstat" == *':'* ]]; then busy=2 next=$curtag while [ $busy != 1 ]; do next=$(($next $dir 1)) checkbound checkbusy done herbstclient use $next else exit fi ;; "all") # switch between all tags next=$(($curtag $dir 1)) checkbound herbstclient use $next ;; *) exit 1 ;; esac