From The Compiler, 10 Years ago, written in Bash.
Embed
  1. #!/bin/bash
  2.  
  3. # Changes herbstluftwm tags
  4.  
  5. checkuse() {
  6.         if [[ "${tags[$1]}" != [.!]* ]]; then # tag is not unused
  7.                 herbstclient use "${tags[$1]:1}" # cutting off first char (.#:!)
  8.                 exit 0
  9.         fi
  10. }
  11.  
  12. tags=( $(herbstclient tag_status) )
  13.  
  14. # Find the currently active tag
  15. for ((i=0; i<="${#tags[@]}"; i++)); do
  16.         [[ "${tags[i]}" == "#"* ]] && activetag="$i"
  17. done
  18.  
  19. if [[ "$1" == next ]]; then # next active tag
  20.         for ((i="$((activetag+1))"; i<"${#tags[@]}"; i++)); do
  21.                 checkuse "$i"
  22.         done
  23.         # at the end of the taglist, wrap around
  24.         for ((i=0; i<"$activetag"; i++)); do
  25.                 checkuse "$i"
  26.         done
  27. elif [[ "$1" == prev ]]; then # previous active tag
  28.         for ((i="$((activetag-1))"; i>=0; i--)) do
  29.                 checkuse "$i"
  30.         done
  31.         # at the beginning of the taglist, wrap around
  32.         for ((i=${#tags[@]}-1; i>$((activetag-1)); i--)) do
  33.                 checkuse "$i"
  34.         done
  35. else
  36.         echo "Usage: $0 [next|prev]"
  37.         exit 1
  38. fi