-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimary_output.sh
executable file
·32 lines (29 loc) · 1.03 KB
/
primary_output.sh
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
#!/bin/sh
# 2015 Sander Boom
# Toggle primary output via xrandr
#
# See: https://wiki.archlinux.org/index.php/xrandr
# connectedOutputs=$(xrandr | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
activeOutputs=$(xrandr | grep -E " connected (primary )?[1-9]+" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
activeOutputs=($activeOutputs) # Create stringarray
primaryOutput=$(xrandr | grep -E " connected primary ?[1-9]+" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
setPrimary() {
xrandr --output "$1" --primary
}
if [ -z "$primaryOutput" ]
then
# primaryOutput is empty, set to first in activeOutputs
echo "No primary detected, setting primary to first possible output: ${activeOutputs[0]}"
setPrimary "${activeOutputs[0]}"
else
# primaryOutput is set, needs to toggle
echo "Current primary: $primaryOutput"
for output in "${activeOutputs[@]}"
do
if [ "$primaryOutput" != "$output" ]
then
echo "Setting primary to: $output"
setPrimary "$output"
fi
done
fi