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