git.infertux.com bin-scripts / master xrandr-auto
master

Tree @master (Download .tar.gz)

xrandr-auto @masterraw · history · blame

#!/bin/bash -eu

IN="eDP1"
CONNECTED_EXT=$(xrandr | grep -Eo "(.+) connected" | sed "s/ connected//" | tail -1)
PREVIOUS_EXT=$(xrandr --listmonitors | tail -1 | awk '{print $NF}')

if [ "$CONNECTED_EXT" = $IN ]; then
    if [ "$PREVIOUS_EXT" != $IN ]; then
        echo "Turning off ${PREVIOUS_EXT}"
        xrandr --output $IN --auto --output "$PREVIOUS_EXT" --off
    fi
else
    echo "Turning on ${CONNECTED_EXT}"
    xrandr --output $IN --auto --primary --output "$CONNECTED_EXT" --auto --above $IN
fi