Skip to content

Instantly share code, notes, and snippets.

@adrianratnapala
Created October 28, 2011 20:56
Show Gist options
  • Save adrianratnapala/1323532 to your computer and use it in GitHub Desktop.
Save adrianratnapala/1323532 to your computer and use it in GitHub Desktop.
Automatic multi-monitor config via xrandr.
#!/bin/sh
# automon.sh -- automatically configures multiple monitors.
#
# I use this script on Arch Linux. This handles my personal monitor setup more
# correctly and robustly than either Ubuntu or Windows 7, however it is only
# designed to work on my laptop.
#
# On that laptop it always calls "xrandr" using the exactly the same arguments.
# The --auto option in xrandr is clever enough to do the rest. One day this
# script might become more flexible.
#
# My laptop is a Lenovo G550 (Model name = 2958).
#
# This gets a list of the form "LVDS1 VGA1 HDMI1 DP1 DP2" -- apparently every
# monitor that the graphics card believes it might theoretically have --
# including the disconnected ones.
OUTS=`xrandr \
| awk '/^[[:alnum:]]+ (dis)?connected/ {print echo $1}' \
| sort`
# LVDS1 is the laptop's built in screen and is therefore different.
OUTP="xrandr --output LVDS1 --auto"
OLD=LVDS1
for OUT in $OUTS
do
# skip the monitor we already configured.
[ "$OUT" == "LVDS1" ] && continue
OUTP="$OUTP --output ${OUT} --auto --left-of $OLD"
#OLD=$OUT
# Since not every monitor can be to the (direct) left of LVDS1, I
# wanted to use $OLD to define a nice linked list. Sure, some of the
# monitors don't exist, but xrandr seems to treat them as 0x0 in size,
# which seems smart to me. Sadly X often crashes when I try this, so
# instead $OLD is always $LVDS1. I suspect this will cause crashes if I
# ever plug more than two monitors in.
done
echo ${OUTP[*]}
@plutopiris23
Copy link

Thanks man. Works like a charm after changing the default screen name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment