Skip to content

Instantly share code, notes, and snippets.

@stchris
Created August 28, 2010 11:20
Show Gist options
  • Save stchris/555025 to your computer and use it in GitHub Desktop.
Save stchris/555025 to your computer and use it in GitHub Desktop.

Revisions

  1. stchris created this gist Aug 28, 2010.
    42 changes: 42 additions & 0 deletions .xprofile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    #!/bin/sh
    # If an external monitor is connected, place it with xrandr
    # Adapted from: http://www.thinkwiki.org/wiki/Xorg_RandR_1.2#Now_automate_it_on_login

    ###### CHANGE THESE

    # External output may be "VGA" or "VGA-0" or "DVI-0" or "TMDS-1"
    EXTERNAL_OUTPUT="VGA1"
    INTERNAL_OUTPUT="LVDS1"
    # Resolution for the external monitor
    EXTERNAL_RES="1920x1080"
    # EXTERNAL_LOCATION may be one of: left, right, above, or below
    EXTERNAL_LOCATION="right"

    ###### DON'T CHANGE THESE

    case "$EXTERNAL_LOCATION" in
    left|LEFT)
    EXTERNAL_LOCATION="--left-of $INTERNAL_OUTPUT"
    ;;
    right|RIGHT)
    EXTERNAL_LOCATION="--right-of $INTERNAL_OUTPUT"
    ;;
    top|TOP|above|ABOVE)
    EXTERNAL_LOCATION="--above $INTERNAL_OUTPUT"
    ;;
    bottom|BOTTOM|below|BELOW)
    EXTERNAL_LOCATION="--below $INTERNAL_OUTPUT"
    ;;
    *)
    EXTERNAL_LOCATION="--left-of $INTERNAL_OUTPUT"
    ;;
    esac

    xrandr |grep $EXTERNAL_OUTPUT | grep " connected "
    if [ $? -eq 0 ]; then
    xrandr --output $INTERNAL_OUTPUT --off --output $EXTERNAL_OUTPUT --auto $EXTERNAL_LOCATION -s $EXTERNAL_RES
    # Alternative command in case of trouble:
    # (sleep 2; xrandr --output $INTERNAL_OUTPUT --auto --output $EXTERNAL_OUTPUT --auto $EXTERNAL_LOCATION) &
    else
    xrandr --output $INTERNAL_OUTPUT --auto --output $EXTERNAL_OUTPUT --off
    fi