#!/bin/sh LIST=`xrandr | sed '/ connected/!d;s/ .*$//'` MONITORS=`printf '%s' "${LIST}" | tr '\n' ' '` CMD="$(FIRST=1 ; for i in ${MONITORS} ; do CURR=`printf '%s' "${LIST}" | sed "/${LAST:=empty}/d" | menu "Next monitor (to right):"` [ -z "${CURR}" ] && exit 0 [ "${FIRST}" ] && printf 'xrandr --output %s' "${CURR}" && FIRST= [ "${LAST}" ] && printf ' --left-of %s' "${CURR}" LAST="${CURR}" done)" $($CMD)