From anonymous, 1 Month ago, written in Bash.
Embed
  1. #!/bin/bash
  2. # vim: set fileencoding=utf-8 ts=4 sts=4 sw=4 tw=80 expandtab :
  3.  
  4. # Copyright (C) 2012 Florian Bruhin <me@the-compiler.org>
  5.  
  6. # tagswitch is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # tagswitch is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with tagswitch  If not, see <http://www.gnu.org/licenses/>.
  18.  
  19. # Changes herbstluftwm tags
  20.  
  21. checkuse() {
  22.     if [[ "${tags[$1]}" != [.!]* ]]; then # tag is not unused
  23.         herbstclient use "${tags[$1]:1}" # cutting off first char (.#:!)
  24.         exit 0
  25.     fi
  26. }
  27.  
  28. tags=( $(herbstclient tag_status) )
  29.  
  30. # Find the currently active tag
  31. for ((i=0; i<="${#tags[@]}"; i++)); do
  32.     [[ "${tags[i]}" == "#"* ]] && activetag="$i"
  33. done
  34.  
  35. if [[ "$1" == next ]]; then # next active tag
  36.     for ((i="$((activetag+1))"; i<"${#tags[@]}"; i++)); do
  37.         checkuse "$i"
  38.     done
  39.     # at the end of the taglist, wrap around
  40.     for ((i=0; i<"$activetag"; i++)); do
  41.         checkuse "$i"
  42.     done
  43. elif [[ "$1" == prev ]]; then # previous active tag
  44.     for ((i="$((activetag-1))"; i>=0; i--)) do
  45.         checkuse "$i"
  46.     done
  47.     # at the beginning of the taglist, wrap around
  48.     for ((i=${#tags[@]}-1; i>$((activetag-1)); i--)) do
  49.         checkuse "$i"
  50.     done
  51. else
  52.     echo "Usage: $0 [next|prev]"
  53.     exit 1
  54. fi
  55.