-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor
executable file
·50 lines (44 loc) · 1.16 KB
/
monitor
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
#!/bin/bash
# switch between 1-monitor- and 2-monitor-mode
# get names and number of currently enabled outputs
IN="eDP1"
EXT="$(xrandr | egrep '\bconnected' | cut -d' ' -f1 | grep -v "$IN" | head -n 1)"
ENABLED=$(xrandr | grep "\*" | cut -d' ' -f1)
COUNT=$(xrandr | grep -c "\*")
# turn off all enabled external monitors that are disconnected
for out in $ENABLED; do
if (xrandr | grep "$out disconnected"); then
xrandr --output "$out" --off
fi
done
external-enable () {
if [ "z$EXT" == "z" ]; then
notify-send "No external monitor available"
return
fi
xrandr --output "$EXT" --auto --above "$IN"
notify-send "Enabled external monitor $EXT"
}
external-disable () {
xrandr --output "$EXT" --off
notify-send "Disabled external monitor $EXT"
}
xrandr --output "$IN" --auto --primary --set "scaling mode" "Full aspect"
case $1 in
enable)
external-enable
;;
disable)
external-disable
;;
*)
# toggle
if [ "$COUNT" -eq 1 ]; then
# if status is empty it's disabled: enable external monitor
external-enable
else
# status is not empty it's enabled: disable external monitor
external-disable
fi
;;
esac