#!/bin/zsh -f if [[ $# -eq 0 ]] ; then echo "switch-layout [ name | list | dmenu | define ]" exit fi LAYOUT=$1 function list-layouts () { for layout in ~/.screenlayout/*.sh ; do echo "$(basename -- ${layout} .sh)" done } function apply-layout () { if [[ -e ~/.screenlayout/${LAYOUT}.sh ]] ; then sh ~/.screenlayout/${LAYOUT}.sh [[ -e ~/.screenlayout/${LAYOUT}.sh-after ]] && \ sh ~/.screenlayout/${LAYOUT}.sh-after echo Switched to ${LAYOUT} layout else echo "${LAYOUT} not available" fi } function with-external-completion () { if [[ -e `which rofi` ]] ; then LAYOUT=`echo define | list-layouts | rofi -dmenu -p layout:` [[ $LAYOUT != "" ]] && apply-layout else LAYOUT=`echo define | list-layouts | dmenu -p layout:` [[ $LAYOUT != "" ]] && apply-layout fi } case ${LAYOUT} in define) arandr ;; list) list-layouts ;; dmenu) with-external-completion ;; *) apply-layout esac