Skip to content

Instantly share code, notes, and snippets.

@zmpeg
Last active December 15, 2015 19:48
Show Gist options
  • Save zmpeg/5313531 to your computer and use it in GitHub Desktop.
Save zmpeg/5313531 to your computer and use it in GitHub Desktop.
extend desktop with xrandr. Usage: ./extend.sh [dir] where [dir] is 'left' or 'right' or 'clone'
#!/bin/bash
if [ -z "$1" ]; then
xrandr --output HDMI1 --mode 0x0
else
RES=`xrandr | grep -A1 HDMI1 | tail -n1 | awk '{ print $1 }'`
echo "Detected HDMI1 with resolution ${RES}"
if [ "$1" == "right" ] || [ "$1" == "left" ]; then
echo "Extending HDMI1 to the {$1} of eDP1"
xrandr --output HDMI1 --mode $RES
sleep 1
xrandr --output HDMI1 --$1-of eDP1
else
if [[ "$1" == "clone" ]]; then
echo "Cloning eDP1 onto HDMI1"
xrandr --output HDMI1 --mode $RES
sleep 1
xrandr --output HDMI1 --same-as eDP1
else
if [[ "$1" == "up" ]]; then
echo "Extending HDMI1 above eDP1"
xrandr --output HDMI1 --mode $RES
sleep 1
xrandr --output HDMI1 --above eDP1
else
echo "Usage: ./extend.sh [dir]"
echo "where [dir] is 'left' or 'right' or 'clone'"
fi
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment