Skip to content

Instantly share code, notes, and snippets.

@PkmX
Created October 13, 2012 11:53
Show Gist options
  • Save PkmX/3884320 to your computer and use it in GitHub Desktop.
Save PkmX/3884320 to your computer and use it in GitHub Desktop.
srandr
#compdef srandr
_arguments "1: :(lvds vga lvds-vga vga-lvds mirror debug)"
#!/usr/bin/env bash
# Simple xrandr
#
# A dirty script to manage my notebook's screen output using xrandr.
# srandr is released under WTFPL (DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE).
lvds=$(xrandr --query | egrep -om1 '^LVDS[0-9]')
vga=$(xrandr --query | egrep -om1 '^VGA[0-9]')
eecho()
{
echo $@ 2>&1
}
if [[ -n $lvds && -n $vga ]]; then
[[ -n $2 ]] && mode1="--mode $2" || mode1='--auto'
[[ -n $3 ]] && mode2="--mode $3" || mode2='--auto'
case $1 in
'lvds')
xrandr --output "$lvds" $mode1 --output "$vga" --off
;;
'vga')
xrandr --output "$lvds" --off --output "$vga" $mode1
;;
'lvds-vga')
xrandr --output "$lvds" $mode1 --output "$vga" $mode2 --right-of "$lvds"
;;
'vga-lvds')
xrandr --output "$lvds" $mode1 --output "$vga" $mode2 --left-of "$lvds"
;;
'mirror')
xrandr --output "$lvds" $mode1 --output "$vga" $mode1 --same-as "$lvds"
;;
'debug')
eecho "LVDS: $lvds"
eecho "VGA: $vga"
;;
*)
eecho "Usage: $(basename $0) [lvds|vga|lvds-vga|vga-lvds|mirror|debug]"
;;
esac
else
eecho 'Unable to find lvds or vga display.'
eecho "LVDS: $lvds"
eecho "VGA: $vga"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment