From anonymous, 1 Month ago, written in Plain Text.
Embed
  1. #!/bin/bash
  2.  
  3. ### "config"
  4. suggestions=(im py tex qb doc vm bsys mail conf dev ssh)
  5. sep="-"  # alternatively e.g. ": "
  6. dmenu="rofi -dmenu"
  7.  
  8.  
  9. old_name=$(herbstclient attr tags.focus.name)
  10. prefix=${old_name%%$sep*}
  11.  
  12. prompt="Rename $prefix"
  13. if [[ "$old_name" == *"$sep"* ]]; then
  14.     old_suffix=${old_name#*$sep}
  15.     prompt+=" ($old_suffix)"
  16.     suggestions=("(clear)" "${suggestions[@]}")
  17. fi
  18.  
  19. new_suffix=$(printf "%s\n" "${suggestions[@]}" | $dmenu -p "$prompt")
  20. case "$new_suffix" in
  21.     "") exit 0 ;;
  22.     "(clear)") new_name="$prefix" ;;
  23.     *) new_name="$prefix$sep$new_suffix" ;;
  24. esac
  25.  
  26. herbstclient try merge_tag "$new_name"  # It might exist already
  27.  
  28. output=$(herbstclient attr tags.focus.name "$new_name" 2>&1)
  29. if [[ $? != 0 ]]; then
  30.     notify-send -u critical "hlwm-namenstag" \
  31.         "<i>Failed to rename \"$old_name\" -> \"$new_name\"</i><br><br>$output"
  32. fi
  33.  
  34. herbstclient emit_hook tag_flags  # Workaround for broken barpyrus