Skip to content

Instantly share code, notes, and snippets.

@porst17
Last active February 21, 2017 08:48
Show Gist options
  • Save porst17/498090724b2653088b064d9dc0d097b7 to your computer and use it in GitHub Desktop.
Save porst17/498090724b2653088b064d9dc0d097b7 to your computer and use it in GitHub Desktop.
Automatically mirror main display to other connected displays
#!/bin/bash
if [ "$#" -lt 2 ]; then
if [ "$#" -eq 1 ]; then
DISPLAYS=`xrandr | grep " connected" | sed "s/ .*$//" | grep -v "$1"`
DISPLAYS="$1 $DISPLAYS"
else
DISPLAYS=`xrandr | grep " connected" | sed "s/ .*$//"`
fi
ARR_DISPLAYS=( $DISPLAYS )
NUM_DISPLAYS=${#ARR_DISPLAYS[@]}
if [ $NUM_DISPLAYS -ge 2 ]; then
exec $0 $DISPLAYS
else
echo Only $NUM_DISPLAYS display found
exit 1
fi
else
MAIN=$1
CMD="xrandr --output $MAIN --auto"
shift
for d in "$@"
do
CMD="$CMD --output $d --auto --same-as $MAIN"
done
notify-send "$CMD"
exec $CMD
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment