Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
toggle your monitors setup between 'extended' and 'mirror' (ideal for pair programming)
#!/bin/bash
# https://gist.github.com/josketres/ff195f4f1d64e7593f04#file-toggle-monitors-sh
# toggle your monitors setup between 'extended' and 'mirror'
# ideal for pair programming sessions
number_of_monitors=`xrandr | grep " connected" | cut -d " " -f 1 | wc -l`
if [ "$number_of_monitors" != "2" ]
then
echo "You should have 2 monitors connected to use this script"
exit 1
fi
screen_1=`xrandr | grep " connected" | cut -d " " -f 1 | head -1`
screen_2=`xrandr | grep " connected" | cut -d " " -f 1 | tail -1`
screen_test=`xrandr | grep " connected" | cut -d " " -f 3 | sort | uniq | wc -l`
if [ "$screen_test" == "1" ]
then
echo "mirror screens - changing to extended screens"
xrandr --output $screen_1 --left-of $screen_2
else
echo "extended screens - changing to mirror screens"
xrandr --output $screen_1 --same-as $screen_2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment