Skip to content

Instantly share code, notes, and snippets.

@dmelo
Last active February 18, 2023 09:35
Show Gist options
  • Save dmelo/47f20170c90e5923c6f3 to your computer and use it in GitHub Desktop.
Save dmelo/47f20170c90e5923c6f3 to your computer and use it in GitHub Desktop.
Shell script to control multiple displays.
#!/bin/bash
# check the main display with xrandr and change this accordingly.
MAIN_DP=eDP1
xrandr --output $MAIN_DP --mode 1920x1080
# list of possible displays. (I have a set of adapters, each is addressed with
# a different name)
LIST=$(xrandr | grep connected | cut -d\ -f 1)
function reset_all {
for OUTPUT in $LIST
do
if [ $OUTPUT != $MAIN_DP ]
then
xrandr --output $OUTPUT --off
fi
done
}
function post_config {
fbsetbg /home/dmelo/wallpaper/one.jpg
}
case $1 in
'dual')
# second monitor at the right side.
reset_all
xrandr --addmode $2 1920x1080
xrandr --output $2 --mode 1920x1080
xrandr --output $2 --right-of $MAIN_DP
post_config
;;
'alone')
# only working with main monitor
reset_all
post_config
;;
'record')
# only one monitor. reduced resolution.
reset_all
xrandr --output $2 --mode 1024x768
;;
'clone')
# mirrored screens
reset_all
xrandr --addmode $2 1920x1080
xrandr --output $2 --mode 1920x1080
post_config
;;
'home')
# second monitor placed above main monitor.
reset_all
xrandr --addmode $2 1920x1080
xrandr --output $2 --mode 1920x1080
xrandr --output $2 --above $MAIN_DP
post_config
;;
*)
echo "Usage:"
echo
echo "./m.sh MODE DISPLAY"
echo
echo " MODE: dual|alone|record|clone|home"
echo " DISPLAY: run xrandr without arguments, to see list of available displays."
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment