12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- #!/bin/zsh -f
- if [[ $# -eq 0 ]] ; then
- echo "i3-workspace-layout [ name workspace | list | define workspace name | edit name | dmenu ]"
- exit
- fi
- LAYOUT=$1
- WORKSPACE=$2
- function define-workspace {
- i3-save-tree --workspace ${WORKSPACE} > ~/.config/i3/layouts/${NAME}.json
- emacsclient --alternate-editor="" -n ~/.config/i3/layouts/${NAME}.json
- }
- function edit-workspace {
- emacsclient --alternate-editor="" -n ~/.config/i3/layouts/${WORKSPACE}.json
- }
- function list-workspaces {
- for layout in ~/.config/i3/layouts/*.json ;
- do
- echo "$(basename -- ${layout} .json)"
- done
- }
- function apply-workspace {
- if [[ -e ~/.config/i3/layouts/${LAYOUT}.json ]] ; then
- i3-msg "append_layout ~/.config/i3/layouts/${LAYOUT}.json"
- [[ -e ~/.config/i3/layouts/${LAYOUT}.after ]] && sh ~/.config/i3/layouts/${LAYOUT}.after
- else
- i3-nagbar -m "${LAYOUT} not available" -t error
- fi
- }
- function apply-workspace-number {
- # i3-msg "workspace number ${WORKSPACENUMBER}"
- if [[ -e ~/.config/i3/layouts/${LAYOUT}.json ]] ; then
- i3-msg "workspace number ${WORKSPACE}; append_layout ~/.config/i3/layouts/${LAYOUT}.json"
- [[ -e ~/.config/i3/layouts/${LAYOUT}.after ]] && sh ~/.config/i3/layouts/${LAYOUT}.after
- else
- i3-nagbar -m "${LAYOUT} not available" -t error
- fi
- }
- function with-external-completion {
- if [[ -e `which rofi` ]] ; then
- LAYOUT=`list-workspaces | rofi -dmenu -p "workspace layout:"`
- [[ $LAYOUT != "" ]] && apply-workspace
- else
- LAYOUT=`list-workspaces | dmenu -p "workspace layout:"`
- [[ $LAYOUT != "" ]] && apply-workspace
- fi
- }
- case ${LAYOUT} in
- define)
- NAME=$3
- define-workspace
- ;;
- edit)
- edit-workspace
- ;;
- list)
- list-workspaces
- ;;
- dmenu)
- with-external-completion
- ;;
- *)
- if [[ $WORKSPACE != "" ]] ; then
- apply-workspace-number
- else
- apply-workspace
- fi
- esac
|