Skip to content

Instantly share code, notes, and snippets.

@Anachron
Created September 25, 2014 09:35
Show Gist options
  • Select an option

  • Save Anachron/4a4d2bb922415949e1bb to your computer and use it in GitHub Desktop.

Select an option

Save Anachron/4a4d2bb922415949e1bb to your computer and use it in GitHub Desktop.
Display Script
#/bin/bash
oldDisplays=""
while [[ 1 ]]
do
displays=$(xrandr | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
if [[ $displays == $oldDisplays ]]
then
sleep 1
continue
fi
active=$(xrandr | grep -e " connected [^(]" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
#primary=$(xrandr| grep -e " primary [^(]" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
#connected=$(echo $displays | wc -w)
#echo "Displays: " $displays
#echo "Active: " $active
#echo "Primary:" $primary
oldDisplays=$displays
#echo "Display switch detected."
killall conky 2&> /dev/null
# External, HDMI + VGA
if [[ $active =~ "HDMI1" && $active =~ "VGA1" ]]
then
$(xrandr --output "eDP1" --off)
$(xrandr --output "VGA1" --auto)
$(xrandr --output "HDMI1" --primary --auto)
# External, HDMI
elif [[ $active =~ "HDMI1" ]]
then
$(xrandr --output "eDP1" --off)
$(xrandr --output "VGA1" --off)
$(xrandr --output "HDMI1" --primary --auto)
# External, VGA
elif [[ $active =~ "VGA1" ]]
then
$(xrandr --output "eDP1" --off)
$(xrandr --output "VGA1" --primary --auto)
$(xrandr --output "HDMI1" --off)
# Only one internal
elif [[ $active =~ "eDP1" ]]
then
$(xrandr --output "eDP1" --primary --auto)
$(xrandr --output "VGA1" --off)
$(xrandr --output "HDMI1" --off)
fi
conky -c /home/eos/.conkyrc 2&> /dev/null
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment