zenUtils/extdisplay.sh

62 lines
1.7 KiB
Bash
Executable file

#!/bin/sh
# extdisplay:
# this is a wrapper around xrandr to handle one external monitor on a laptop
# Derek Stevens <nilix@nilfm.cc>
# MIT License
helpme()
{
echo "$0, wrapper for using xrandr to handle an external display on a laptop"
echo ""
echo "USAGE: $0 solo|off|left-of|right-of|above|below [res]"
echo " status\n prints connected/disconnected depending on if there is a monitor plugged in"
echo " solo\n activates the plugged monitor, deactivates the native display"
echo " off\n activates the native display, deactivates the plugged monitor"
echo " left-of, right-of, above, below\n activates the plugged monitor in the given"
echo " relation to the native display"
echo " res\n if included, sets the resolution of the plugged monitor"
}
if [ -z $1 ]; then
helpme
exit 0
fi
native=$(xrandr | grep LVDS | awk '{print $1}')
plugged=$(xrandr | grep connected | grep -v disconnected | grep -v ${native} | awk '{print $1}')
if [ "$1" = solo ]; then
xrandr --output ${plugged} --primary
xrandr --output ${native} --off
xrandr --output ${plugged} --auto
if [ ! -z $2 ]; then
xrandr -s $2
fi
elif [ "$1" = off ]; then
xrandr --output ${native} --primary
xrandr --output ${plugged} --off
xrandr --output ${native} --auto
elif [ "$1" = status ]; then
if [ -z "$(xrandr | grep connected | grep -v disconnected | grep -v LVDS)" ]; then
echo "disconnected"
else
echo "connected"
fi
else
case $1 in
right-of|left-of|above|below)
xrandr --output ${native} --auto --output ${plugged} --auto --$1 ${native}
if [ ! -z $2 ]; then
xrandr --output ${plugged} -s $2
fi
;;
*)
helpme
;;
esac
fi