i3-layout 1.4 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. else
  33. LAYOUT=`list-workspaces | dmenu -p "workspace layout:"`
  34. [[ $LAYOUT != "" ]] && apply-workspace
  35. fi
  36. }
  37. case ${LAYOUT} in
  38. define)
  39. NAME=$3
  40. define-workspace
  41. ;;
  42. edit)
  43. edit-workspace
  44. ;;
  45. list)
  46. list-workspaces
  47. ;;
  48. dmenu)
  49. with-external-completion
  50. ;;
  51. *)
  52. apply-workspace
  53. esac