forked from termux/termux-x11
-
Notifications
You must be signed in to change notification settings - Fork 0
/
termux-x11-preference
executable file
·51 lines (45 loc) · 1.21 KB
/
termux-x11-preference
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
#!/data/data/com.termux/files/usr/bin/bash
COMMAND=("am" "broadcast" "-a" "com.termux.x11.CHANGE_PREFERENCE" "-p" "com.termux.x11")
help() {
echo "$0 {list} {key:value}..."
exit 1
}
list() {
output="$("${COMMAND[@]}" -e list null 2>&1)"
result=$(sed -n '/result=[0-9]*/{s/.*result=\([0-9]*\).*/\1/p;q;}' <<< "$output")
if [[ "$result" == "0" ]]; then
echo "Something went wrong."
exit 1
fi
if [[ "$result" == "2" ]] || [[ "$result" == "4" ]]; then
echo "$(echo "$output" | sed -z 's/.*data="\([^"]*\)*/\1/' | sed '${s/"$//}')"
exit 0
fi
echo "list: Unexpected result $result"
echo "$output"
exit 1
}
if [ $# -eq 0 ]; then
help
fi
while [[ $# -gt 0 ]]; do
case $1 in
list) list;;
*:*) COMMAND+=("-e" "${1%%:*}" "${1#*:}");;
*) echo "Unrecognised option $1"; help
esac
shift
done
output="$("${COMMAND[@]}")"
result=$(sed -n '/result=[0-9]*/{s/.*result=\([0-9]*\).*/\1/p;q;}' <<< "$output")
if [[ "$result" == "0" ]]; then
echo "Something went wrong."
exit 1
fi
if [[ "$result" == "2" ]] || [[ "$result" == "4" ]]; then
echo "$(echo "$output" | sed -z 's/.*data="\([^"]*\)*/\1/' | sed '${s/"$//}')"
exit 0
fi
echo "set: Unexpected result $result"
echo "$output"
exit 1