Skip to content

Instantly share code, notes, and snippets.

@kelnos
Created January 10, 2013 10:03
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 kelnos/4500899 to your computer and use it in GitHub Desktop.
Save kelnos/4500899 to your computer and use it in GitHub Desktop.
script to toggle ext monitor on and offf
#!/bin/bash
set -ex
stuff=$(xrandr | grep -v -E '^eDP1' | grep ' connected') && have_ext=yes || have_ext=no
if [ "$have_ext" = "no" ]; then
# just make sure it's off
for op in $(xrandr | awk '/disconnected/ { print $1 }'); do
xrandr --output $op --off
done
else
# FIXME: if i somehow have more than one ext monitor connected...
op=$(echo "$stuff" | cut -d' ' -f1)
echo "$stuff" | grep -q -E '[[:digit:]]+x[[:digit:]]+' && connected=yes || connected=no
if [ "$connected" = "yes" ]; then
xrandr --output $op --off
else
xrandr --output $op --preferred --right-of eDP1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment