all repos — zenUtils @ 571d2b0d95ccc03a2c63a27a2e3b3222979ed752

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
#!/bin/sh

# extdisplay:
# this is a wrapper around xrandr to handle one external monitor on a laptop
# copyleft 2020 Derek Stevens <drkste@zoho.com>
# MIT License -- do whatever you want

helpme()
{
  echo  "$0, wrapper for using xrandr to handle an external on a laptop"
  echo  ""
  echo  "USAGE: $0 solo|off|left-of|right-of|above|below [res]"
  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
fi

native=xrandr | grep LVDS | awk '{print $1}'
plugged=xrandr | grep connected | 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

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