Skip to content

Instantly share code, notes, and snippets.

@Ivoz

Ivoz/screens.sh

Created May 26, 2014
Embed
What would you like to do?
Do xrandr stuff
#!/bin/bash
laptop_screen="LVDS1"
external_screen="HDMI1"
position="left"
if [[ ! -z "$1" ]]; then
external_screen="$1"
fi
xr_conn=$(xrandr -q | grep -w "connected")
xr_disconn=$(xrandr -q | grep -w "disconnected")
# Configure screens to be their default resolution
while read -r line; do
monitor=$(echo "$line" | cut -f1 -d" ")
xrandr --output "$monitor" --auto
done <<< "$xr_conn"
# Turn off disconnected screens
while read -r line; do
monitor=$(echo "$line" | cut -f1 -d" ")
xrandr --output "$monitor" --off
done <<< "$xr_disconn"
# Configure external screen to be left of laptop, if both present
if [[ "$xr_conn" =~ "$laptop_screen connected" ]] && [[ "$xr_conn" =~ "$external_screen connected" ]]; then
xrandr --output "$laptop_screen" --"$position"-of "$external_screen"
xrandr --output "$external_screen" --primary
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment