zenUtils/extdisplay.sh

63 lines
1.7 KiB
Bash
Raw Normal View History

2020-08-05 04:57:45 +00:00
#!/bin/sh
# extdisplay:
# this is a wrapper around xrandr to handle one external monitor on a laptop
# Derek Stevens <nilix@nilfm.cc>
# MIT License
2020-08-05 04:57:45 +00:00
helpme()
{
2022-01-14 04:57:24 +00:00
echo "$0, wrapper for using xrandr to handle an external display on a laptop"
2020-08-05 04:57:45 +00:00
echo ""
echo "USAGE: $0 solo|off|left-of|right-of|above|below [res]"
2022-01-14 04:57:24 +00:00
echo " status\n prints connected/disconnected depending on if there is a monitor plugged in"
2020-08-05 04:57:45 +00:00
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
2021-03-27 23:47:51 +00:00
exit 0
2020-08-05 04:57:45 +00:00
fi
2021-03-27 23:47:51 +00:00
native=$(xrandr | grep LVDS | awk '{print $1}')
plugged=$(xrandr | grep connected | grep -v disconnected | grep -v ${native} | awk '{print $1}')
2020-08-05 04:57:45 +00:00
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
2022-01-14 04:57:24 +00:00
elif [ "$1" = status ]; then
if [ -z "$(xrandr | grep connected | grep -v disconnected | grep -v LVDS)" ]; then
echo "disconnected"
else
echo "connected"
fi
2020-08-05 04:57:45 +00:00
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
2020-08-05 04:57:45 +00:00
;;
*)
helpme
;;
esac
fi