i3-workspace-layout 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/zsh -f
  2. if [[ $# -eq 0 ]] ; then
  3. echo "i3-workspace-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 apply-workspace-number {
  30. # i3-msg "workspace number ${WORKSPACENUMBER}"
  31. if [[ -e ~/.config/i3/layouts/${LAYOUT}.json ]] ; then
  32. i3-msg "workspace number ${WORKSPACE}; append_layout ~/.config/i3/layouts/${LAYOUT}.json"
  33. [[ -e ~/.config/i3/layouts/${LAYOUT}.after ]] && sh ~/.config/i3/layouts/${LAYOUT}.after
  34. else
  35. i3-nagbar -m "${LAYOUT} not available" -t error
  36. fi
  37. }
  38. function with-external-completion {
  39. if [[ -e `which rofi` ]] ; then
  40. LAYOUT=`list-workspaces | rofi -dmenu -p "workspace layout:"`
  41. [[ $LAYOUT != "" ]] && apply-workspace
  42. else
  43. LAYOUT=`list-workspaces | dmenu -p "workspace layout:"`
  44. [[ $LAYOUT != "" ]] && apply-workspace
  45. fi
  46. }
  47. case ${LAYOUT} in
  48. define)
  49. NAME=$3
  50. define-workspace
  51. ;;
  52. edit)
  53. edit-workspace
  54. ;;
  55. list)
  56. list-workspaces
  57. ;;
  58. dmenu)
  59. with-external-completion
  60. ;;
  61. *)
  62. if [[ $WORKSPACE != "" ]] ; then
  63. apply-workspace-number
  64. else
  65. apply-workspace
  66. fi
  67. esac