Skip to content

Instantly share code, notes, and snippets.

@zopieux
Created May 27, 2016 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zopieux/040b31c1a4fff6d921bca1cd78942d92 to your computer and use it in GitHub Desktop.
Save zopieux/040b31c1a4fff6d921bca1cd78942d92 to your computer and use it in GitHub Desktop.
Laptop screen & (VGA | HDMI) toggle
#!/bin/sh
main=LVDS1
a=VGA1
b=HDMI1
dir=left
function on {
echo Switching $1 on
xrandr --output $1 --auto --$dir-of $main
}
function off {
echo Switching $1 off
xrandr --output $1 --off
}
function check {
xrandr | egrep "$1 connected" >/dev/null
echo $?
}
outa=$(check $a)
outb=$(check $b)
[[ $outa -ne 0 ]] && off $a
[[ $outb -ne 0 ]] && off $b
[[ $outa -ne 0 && $outb -ne 0 ]] && exit
[[ $outa -eq 0 && $outb -ne 0 ]] && on $a && exit
[[ $outa -ne 0 && $outb -eq 0 ]] && on $b && exit
xrandr | egrep "$a connected [0-9]+" >/dev/null
outa=$?
xrandr | egrep "$b connected [0-9]+" >/dev/null
outb=$?
if [[ $outa -eq 0 ]]; then
off $a
on $b
else
off $b
on $a
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment