1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #!/bin/zsh -f
- if [[ $# -eq 0 ]] ; then
- echo "i3-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 with-external-completion {
- if [[ -e `which rofi` ]] ; then
- LAYOUT=`list-workspaces | rofi -dmenu -p "workspace layout:"`
- 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
- ;;
- *)
- apply-workspace
- esac
|