Created
May 27, 2016 20:40
-
-
Save zopieux/040b31c1a4fff6d921bca1cd78942d92 to your computer and use it in GitHub Desktop.
Laptop screen & (VGA | HDMI) toggle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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