executable_sway-workspaces 795 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env bash
  2. shopt -s nullglob globstar
  3. stringContain()
  4. {
  5. [ -z "$1" ] || { [ -z "${2##*"$1"*}" ] && [ -n "$2" ];}
  6. }
  7. menu()
  8. {
  9. bemenu \
  10. --fb '#000000' \
  11. --ab '#000000' \
  12. --tb '#000000' \
  13. --nb '#000000' \
  14. --tf '#ffffff' \
  15. --hf '#ffffff' \
  16. --hb '#2e8b57' \
  17. --border 1 \
  18. --bdr '#333333' \
  19. --line-height 25 \
  20. --hp 10 \
  21. --fn "DejaVu Sans Mono 10" \
  22. --list 20 \
  23. --center \
  24. --no-spacing \
  25. --prompt "sway-workspaces"
  26. }
  27. mapfile -t workspaces < <(swaymsg -t get_tree | jq '.nodes[] | .nodes[] | .num | select(.)' | sort --version-sort)
  28. workspace=$(printf '%s\n' "${workspaces[@]}" | menu "$@")
  29. [[ -n $workspace ]] || exit
  30. workspace "$workspace" 2>/dev/null