i3-layout 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/zsh -f
  2. if [[ $# -eq 0 ]] ; then
  3. echo "i3-layout [ name workspace | list | define workspace name | edit name | dmenu ]"
  4. exit
  5. fi
  6. LAYOUT=$1
  7. WORKSPACE=$2
  8. function define-workspace {
  9. i3-save-tree --workspace ${WORKSPACE} > ~/.config/i3/layouts/${NAME}.json
  10. emacsclient --alternate-editor="" -n ~/.config/i3/layouts/${NAME}.json
  11. }
  12. function edit-workspace {
  13. emacsclient --alternate-editor="" -n ~/.config/i3/layouts/${WORKSPACE}.json
  14. }
  15. function list-workspaces {
  16. for layout in ~/.config/i3/layouts/*.json ;
  17. do
  18. echo "$(basename -- ${layout} .json)"
  19. done
  20. }
  21. function apply-workspace {
  22. if [[ -e ~/.config/i3/layouts/${LAYOUT}.json ]] ; then
  23. i3-msg "append_layout ~/.config/i3/layouts/${LAYOUT}.json"
  24. [[ -e ~/.config/i3/layouts/${LAYOUT}.after ]] && sh ~/.config/i3/layouts/${LAYOUT}.after
  25. else
  26. i3-nagbar -m "${LAYOUT} not available" -t error
  27. fi
  28. }
  29. function with-external-completion {
  30. if [[ -e `which rofi` ]] ; then
  31. LAYOUT=`list-workspaces | rofi -dmenu -p "workspace layout:"`
  32. [[ $LAYOUT != "" ]] && apply-workspace
  33. else
  34. LAYOUT=`list-workspaces | dmenu -p "workspace layout:"`
  35. [[ $LAYOUT != "" ]] && apply-workspace
  36. fi
  37. }
  38. case ${LAYOUT} in
  39. define)
  40. NAME=$3
  41. define-workspace
  42. ;;
  43. edit)
  44. edit-workspace
  45. ;;
  46. list)
  47. list-workspaces
  48. ;;
  49. dmenu)
  50. with-external-completion
  51. ;;
  52. *)
  53. apply-workspace
  54. esac