1#!/bin/bash23XRANDR=$(which xrandr)45MONITORS=( $( ${XRANDR} | awk '( $2 == "connected" ){ print $1 }' ) )678NUM_MONITORS=${#MONITORS[@]}910TITLES=()11COMMANDS=()121314function gen_xrandr_only()15{16 selected=$11718 cmd="xrandr --output ${MONITORS[$selected]} --auto "1920 for entry in $(seq 0 $((${NUM_MONITORS}-1)))21 do22 if [ $selected != $entry ]23 then24 cmd="$cmd --output ${MONITORS[$entry]} --off"25 fi26 done2728 echo $cmd29}30313233declare -i index=034TILES[$index]="Cancel"35COMMANDS[$index]="true"36index+=1373839for entry in $(seq 0 $((${NUM_MONITORS}-1)))40do41 TILES[$index]="Only ${MONITORS[$entry]}"42 COMMANDS[$index]=$(gen_xrandr_only $entry)43 index+=144done4546##47# Dual screen options48##49for entry_a in $(seq 0 $((${NUM_MONITORS}-1)))50do51 for entry_b in $(seq 0 $((${NUM_MONITORS}-1)))52 do53 if [ $entry_a != $entry_b ]54 then55 TILES[$index]="Dual Screen ${MONITORS[$entry_a]} -> ${MONITORS[$entry_b]}"56 COMMANDS[$index]="xrandr --output ${MONITORS[$entry_a]} --auto \57 --output ${MONITORS[$entry_b]} --auto --left-of ${MONITORS[$entry_a]}"5859 index+=160 fi61 done62done636465##66# Clone monitors67##68for entry_a in $(seq 0 $((${NUM_MONITORS}-1)))69do70 for entry_b in $(seq 0 $((${NUM_MONITORS}-1)))71 do72 if [ $entry_a != $entry_b ]73 then74 TILES[$index]="Clone Screen ${MONITORS[$entry_a]} -> ${MONITORS[$entry_b]}"75 COMMANDS[$index]="xrandr --output ${MONITORS[$entry_a]} --auto \76 --output ${MONITORS[$entry_b]} --auto --same-as ${MONITORS[$entry_a]}"7778 index+=179 fi80 done81done828384##85# Generate entries, where first is key.86##87function gen_entries()88{89 for a in $(seq 0 $(( ${#TILES[@]} -1 )))90 do91 echo $a ${TILES[a]}92 done93}9495# Call menu96SEL=$( gen_entries | rofi -dmenu -p "Monitor Setup:" -a 0 -no-custom | awk '{print $1}' )9798# Call xrandr99$( ${COMMANDS[$SEL]} )