Skip to content

Instantly share code, notes, and snippets.

@johntyree
Created March 14, 2013 17:51
Show Gist options
  • Save johntyree/5163520 to your computer and use it in GitHub Desktop.
Save johntyree/5163520 to your computer and use it in GitHub Desktop.
Easy xRandr settings.
#!/bin/sh
# GistID: 5163520
usage () {
echo "Usage: $0 OPTION
Change multi-head display settings.
Options:
-a Do something reasonable
-0 Laptop
-1 Laptop + VGA
-2 Laptop + Rotated VGA
-3 Laptop + DisplayPort
-4 Laptop + Rotated DisplayPort
-5 VGA + DisplayPort
-6 VGA + Rotated DisplayPort
-7 Rotated VGA + Rotated DisplayPort
-8 DisplayPort + Rotated VGA
-9 Rotated DisplayPort + Rotated VGA"
}
args=()
kill_display() {
while [[ $# > 0 ]]; do
args+=(--output "$1" --off)
shift
done
}
main() {
args+=(--output "$1" --primary --rotate "$2" --pos 0x0 --auto)
}
aux() {
args+=(--output "$1" --rotate "$2" --right-of "$3" --auto)
}
if [[ $# == 0 ]]; then
usage
exit 1
fi
while getopts ":0123456789a" opt; do
case $opt in
0)
kill_display DP1 VGA1
main LVDS1 normal
;;
1)
kill_display DP1
main LVDS1 normal
aux VGA1 normal LVDS1
;;
2)
kill_display DP1
main LVDS1 normal
aux VGA1 left LVDS1
;;
3)
kill_display VGA1
main LVDS1 normal
aux DP1 normal LVDS1
;;
4)
kill_display VGA1
main LVDS1 normal
aux DP1 left LVDS1
;;
5)
kill_display LVDS1
main VGA1 normal
aux DP1 normal VGA1
;;
6)
kill_display LVDS1
main VGA1 normal
aux DP1 left VGA1
;;
7)
kill_display LVDS1
main VGA1 left
aux DP1 left VGA1
;;
8)
kill_display LVDS1
main DP1 normal
aux VGA1 left DP1
;;
9)
kill_display LVDS1
main DP1 left
aux VGA1 left DP1
;;
a)
disp=($(xrandr | perl -nE 'say $1 if /(\w+) connected/ and not /^LVDS/'))
nodisp=($(xrandr | perl -nE 'say $1 if /(\w+) disconnected/'))
echo ${disp[@]} ${#disp[@]}
if [[ ${#disp[@]} == 2 ]]; then
kill_display LVDS1
main $disp[0] normal
aux $disp[1] normal $disp[0]
elif [[ ${#disp[@]} == 1 ]]; then
kill_display ${nodisp[@]}
main LVDS1 normal
aux $disp normal LVDS1
else
kill_display ${nodisp[@]}
main LVDS1 normal
fi
;;
\?)
usage
exit 1
;;
esac
done
echo xrandr "${args[@]}"
xrandr "${args[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment