all repos — zenUtils @ main

misc utilities for computing zen

extdisplay.sh (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh

# extdisplay:
# this is a wrapper around xrandr to handle one external monitor on a laptop
# Derek Stevens <nilix@nilfm.cc>
# MIT License

helpme()
{
  echo  "$0, wrapper for using xrandr to handle an external display on a laptop"
  echo  ""
  echo  "USAGE: $0 solo|off|left-of|right-of|above|below [res]"
  echo  "  status\n    prints connected/disconnected depending on if there is a monitor plugged in"
  echo  "  solo\n    activates the plugged monitor, deactivates the native display"
  echo  "  off\n    activates the native display, deactivates the plugged monitor"
  echo  "  left-of, right-of, above, below\n    activates the plugged monitor in the given"
  echo  "    relation to the native display"
  echo  "  res\n    if included, sets the resolution of the plugged monitor"
}

if [ -z $1 ]; then
  helpme
  exit 0
fi

native=$(xrandr | grep LVDS | awk '{print $1}')
plugged=$(xrandr | grep connected | grep -v disconnected | grep -v ${native} | awk '{print $1}')

if [ "$1" = solo ]; then
  xrandr --output ${plugged} --primary
  xrandr --output ${native} --off
  xrandr --output ${plugged} --auto
  if [ ! -z $2 ]; then
    xrandr -s $2
  fi

elif [ "$1" = off ]; then
  xrandr --output ${native} --primary
  xrandr --output ${plugged} --off
  xrandr --output ${native} --auto

elif [ "$1" = status ]; then
  if [ -z "$(xrandr | grep connected | grep -v disconnected | grep -v LVDS)" ]; then
    echo "disconnected"
  else
    echo "connected"
  fi

else
  case $1 in
    right-of|left-of|above|below)
      xrandr --output ${native} --auto --output ${plugged} --auto --$1 ${native}
      if [ ! -z $2 ]; then
        xrandr --output ${plugged} -s $2
      fi
      ;;
    *)
      helpme
      ;;
  esac
fi