switch-layout 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/zsh -f
  2. if [[ $# -eq 0 ]] ; then
  3. echo "switch-layout [ name | list | dmenu | define ]"
  4. exit
  5. fi
  6. LAYOUT=$1
  7. function list-layouts () {
  8. for layout in ~/.screenlayout/*.sh ;
  9. do
  10. echo "$(basename -- ${layout} .sh)"
  11. done
  12. }
  13. function apply-layout () {
  14. if [[ -e ~/.screenlayout/${LAYOUT}.sh ]] ; then
  15. sh ~/.screenlayout/${LAYOUT}.sh
  16. [[ -e ~/.screenlayout/${LAYOUT}.sh-after ]] && \
  17. sh ~/.screenlayout/${LAYOUT}.sh-after
  18. echo Switched to ${LAYOUT} layout
  19. else
  20. echo "${LAYOUT} not available"
  21. fi
  22. }
  23. function with-external-completion () {
  24. if [[ -e `which rofi` ]] ; then
  25. LAYOUT=`echo define | list-layouts | rofi -dmenu -p layout:`
  26. [[ $LAYOUT != "" ]] && apply-layout
  27. else
  28. LAYOUT=`echo define | list-layouts | dmenu -p layout:`
  29. [[ $LAYOUT != "" ]] && apply-layout
  30. fi
  31. }
  32. case ${LAYOUT} in
  33. define)
  34. arandr
  35. ;;
  36. list)
  37. list-layouts
  38. ;;
  39. dmenu)
  40. with-external-completion
  41. ;;
  42. *)
  43. apply-layout
  44. esac