Skip to content

Instantly share code, notes, and snippets.

@remvee
Created June 2, 2016 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remvee/1b6f98b13ed984cc9fc747a9a78ce340 to your computer and use it in GitHub Desktop.
Save remvee/1b6f98b13ed984cc9fc747a9a78ce340 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Monitor hotplug for my Thinkpad X240 / Arch Linux / AwesomeWM setup.
#
# Create /etc/udev/rules.d/99-monitor-hotplug.rules with following content:
#
# ACTION=="change", SUBSYSTEM=="drm", ENV{HOTPLUG}=="1", RUN+="/home/me/bin/monitor-hotplug"
touch /tmp/monitor-hotplug.log
chmod a+w /tmp/monitor-hotplug.log
echo monitor-hotplug: `date` >> /tmp/monitor-hotplug.log
exec >> /tmp/monitor-hotplug.log 2>&1
set -x
if [ -z "$DISPLAY" ]; then
export DISPLAY=:0
export XAUTHORITY="$(dirname $(dirname $0))/.Xauthority"
sleep 3
fi
OTHER=`xrandr | awk '/ connected /{print$1}' | grep -v eDP1`
if [ -z "$OTHER" ]; then
ARGS=""
for DP in `xrandr | awk '/connected/{print$1}' | grep -v eDP1`; do
ARGS="$ARGS --output $DP --off"
done
xrandr --output eDP1 --auto $ARGS
else
xrandr --output eDP1 --auto --output $OTHER --auto --right-of eDP1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment