-
Notifications
You must be signed in to change notification settings - Fork 9
/
grml-resolution
executable file
·62 lines (50 loc) · 1.6 KB
/
grml-resolution
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
54
55
56
57
58
59
60
61
62
#!/bin/bash
# Filename: grml-resolution
# Purpose: change X resolution via a simple menu frontend
# Authors: Florian Keller <florian.keller@zuerich.ch>, (c) Michael Prokop <mika@grml.org>
# Bug-Reports: see http://grml.org/bugs/
# License: This file is licensed under the GPL v2.
################################################################################
PN="$(basename "$0")"
RESOLUTION=$(mktemp)
ERROR=$(mktemp)
bailout(){
rm -f "$RESOLUTION" "$ERROR"
exit "$1"
}
trap bailout 1 2 3 15
main(){
# menu
COUNTER=0
STRING=""
# current mode
CURRENT_NUM=$(xrandr | awk '/\*/ {print $1}' | tr -d '*')
CURRENT_RESOLUTION=$(xrandr | awk '/\*/ {print $2 $3 $4}')
# menu
for i in $(xrandr | awk '{print $2$3$4}' | grep "^[0-9]") ; do
STRING="$STRING $COUNTER $i"
((COUNTER++))
done
# Menu Tool
# shellcheck disable=SC2086
dialog --title "$PN" --menu "Change X resolution via xrandr (current resolution: $CURRENT_RESOLUTION):" 0 0 0 $STRING 2>"$RESOLUTION"
retval=$?
case $retval in
(1) echo "Cancel pressed." ; exit 1 ;;
(255) echo "ESC pressed." ; exit 1 ;;
esac
CHOSE=$(cat "$RESOLUTION")
if [ "$CHOSE" = "$CURRENT_NUM" ] ; then
dialog --title "$PN" --msgbox "Chosen resolution corresponds to current resolution. No changes needed." 0 0
elif [ -n "$CHOSE" ] ; then
# shellcheck disable=SC2015
xrandr -s "$CHOSE" 2>"$ERROR" && \
dialog --title "$PN" --msgbox "Running xrandr with resolution was succesful." 0 0 || \
dialog --title "$PN" --msgbox "Error when running xrandr with resolution $CHOSE: $(cat "$ERROR")" 0 0
fi
}
while true ; do
main
done
bailout 0
# EOF #