addresolution 870 Bytes
Newer Older
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

showExample() { 
    echo -e "\ne.g. \""$(basename -- "$0")" 1920 1080 60\"\n"
}

createRes() {
    cvt "$WIDTH" "$HEIGHT" "$REFRESH" | grep Modeline | sed "s/Modeline//" | xargs xrandr --newmode
}

addRes() {
    xrandr --addmode eDP1 "$WIDTH"x"$HEIGHT"_"$REFRESH".00
}

# check arguments
if [ -z "$1" ]; then
    echo "Please provide a screen width as the first argument"
    showExample
    exit 128
fi

if [ -z "$2" ]; then
    echo "Please provide a screen height as the second argument"
    showExample
    exit 128
fi

if [ -z "$3" ]; then
    echo "Please provide a refresh rate as the third argument"
    showExample
    exit 128
fi

#init
WIDTH=$1
HEIGHT=$2
REFRESH=$3

createRes || {
    echo -e "\nERROR creating resolution with \"cvt\"\n"
    exit 1
}

addRes || {
    echo -e "\nERROR adding resolution with \"xrandr\"\n"
    exit 1
}

exit 0