OSDN Git Service

add youtube-dl and xclip
[instantos/instantOS.git] / monitor.sh
1 #!/bin/bash
2
3 command -v xrandr &>/dev/null ||
4     (echo "please install xrandr" && exit 1)
5 cd
6
7 mkdir -p ~/instantos/monitor &>/dev/null
8 cd ~/instantos/monitor
9
10 xrandr | grep '[^s]connected' | grep -o '[0-9]*x[0-9]*+[0-9]*' | grep -o '[0-9]*$' >positions.txt
11 AMOUNT=$(cat positions.txt | wc -l)
12
13 # get monitor with highest resolution
14 xrandr | grep '[^s]connected' | grep -Eo '[0-9]{1,}x[0-9]{1,}\+[0-9]{1,}\+[0-9]{1,}' |
15     grep -o '[0-9]*x[0-9]*' >resolutions.txt
16
17 if [ $(cat resolutions.txt | sort -u | wc -l) = "1" ]; then
18     echo "resolutions identical"
19     head -1 resolutions.txt >max.txt
20 else
21     let PIXELS1="$(head -1 resolutions.txt | grep -o '^[0-9]*') * $(cat resolutions.txt | head -1 | grep -o '[0-9]*$')"
22     let PIXELS2="$(tail -1 resolutions.txt | grep -o '^[0-9]*') * $(cat resolutions.txt | head -1 | grep -o '[0-9]*$')"
23     if [ "$PIXELS1" -gt "$PIXELS2" ]; then
24         head -1 resolutions.txt >max.txt
25     else
26         tail -1 resolutions.txt >max.txt
27     fi
28 fi
29
30 if [ "$AMOUNT" = "1" ]; then
31     echo "only one monitor found, further setup not needed"
32     exit
33 else
34     if [ "$AMOUNT" -gt 2 ]; then
35         echo "only 2 monitors are supported"
36         exit
37     fi
38     echo "$AMOUNT monitors found"
39 fi
40
41 xrandr | grep '[^s]connected' | grep -o '^[^ ]*' >names.txt
42 MONITOR1=$(head -1 positions.txt)
43 MONITOR2=$(tail -1 positions.txt)
44
45 if [ "$MONITOR1" -gt "$MONITOR2" ]; then
46     echo "Monitor 1 is ${MONITOR1}px on the right"
47     echo "$MONITOR1" >right.txt
48 else
49     echo "Monitor 2 is ${MONITOR2}px on the right"
50     echo "$MONITOR1" >right.txt
51 fi