Skip to content

Instantly share code, notes, and snippets.

@Ivoz
Created May 26, 2014 11:05
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 Ivoz/c1a207f7ca362ee793a7 to your computer and use it in GitHub Desktop.
Save Ivoz/c1a207f7ca362ee793a7 to your computer and use it in GitHub Desktop.
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