i3-screen-layout 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/sh
  2. if [[ $# -eq 0 ]] ; then
  3. echo "i3-screen-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