Skip to content

Instantly share code, notes, and snippets.

@xurizaemon xurizaemon/x-displays.sh
Last active Aug 26, 2018

Embed
What would you like to do?
#!/bin/bash
# Unity doesn't remember my screen layouts, so I made this to do it for me.
#
# https://gist.github.com/e1892192ea8dd03a210d2890f8f966e7
#
# GPLv3+, (c) Chris Burgess @xurizaemon
#
# To update on gist.github.com:
# `gist -u https://gist.github.com/e1892192ea8dd03a210d2890f8f966e7 ~/bin/x-displays.sh`
CONNECTED=$( xrandr | grep ' connected' )
LAYOUT=unknown
if [[ $CONNECTED = *"DP-2-1"* ]] ; then
if [[ $CONNECTED = *"DP-2-2"* ]] ; then
LAYOUT=dock_displayport_both
fi
elif [[ $CONNECTED = *"DP-2-3"* ]] ; then
if [[ $CONNECTED = *"DP-2-1"* ]] ; then
LAYOUT=dock_vga_hdmi
fi
elif [[ $CONNECTED = *"HDMI-2 connected"* ]] ; then
LAYOUT=hdmi-2
elif [[ $CONNECTED = *"DP-1 connected"* ]] ; then
LAYOUT=thunderbolt
fi
case "$LAYOUT" in
"dock_displayport_both")
# Displayport 1, 2, laptop
xrandr --output DP-2-2 --auto --left-of eDP-1
xrandr --output DP-2-1 --auto --left-of DP-2-2 --primary
echo "Configured for $LAYOUT"
;;
"dock_vga_hdmi")
# HDMI, VGA, laptop
xrandr --output DP-2-3 --auto --left-of eDP-1
xrandr --output DP-2-1 --auto --left-of DP-2-3 --primary
echo "Configured for $LAYOUT"
;;
"thunderbolt")
# Thunderbolt, laptop
xrandr --output DP-1 --auto --left-of eDP-1 --primary
echo "Configured for $LAYOUT"
;;
"hdmi-2")
# Set to 57Hz for monitor support
xrandr --newmode "1920x1080_57.00" 163.00 1920 2040 2240 2560 1080 1083 1088 1119 -hsync +vsync
xrandr --addmode HDMI-2 "1920x1080_57.00"
# HDMI, laptop
xrandr --output HDMI-2 --mode "1920x1080_57.00" --left-of eDP-1 --primary
echo "Configured for $LAYOUT"
;;
*)
echo "Layout $LAYOUT not known."
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.