~mil/sxmo-utils

ref: dbc3b1ab509aab5f1db72c5cece2ee2a6eb521e8 sxmo-utils/scripts/core/sxmo_statusbar.sh -rwxr-xr-x 2.8 KiB
dbc3b1abStacy Harper Allow the sendnewtextmenu to be used with a number as arg 1 year, 4 months ago
                                                                                
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env sh

# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"

trap "update" USR1
pgrep -f sxmo_statusbar.sh | grep -v $$ | xargs -r kill -9

update() {
	# In-call.. show length of call
	CALLINFO=" "
	if pgrep -f sxmo_modemcall.sh; then
		NOWS="$(date +"%s")"
		CALLSTARTS="$(date +"%s" -d "$(
			grep -aE 'call_start|call_pickup' "$XDG_DATA_HOME"/sxmo/modem/modemlog.tsv |
			tail -n1 |
			cut -f1
		)")"
		CALLSECONDS="$(echo "$NOWS" - "$CALLSTARTS" | bc)"
		CALLINFO="${CALLSECONDS}s"
	fi

	# W symbol if wireless is connect
	WIRELESS=""
	WLANSTATE="$(tr -d "\n" < /sys/class/net/wlan0/operstate)"
	if [ "$WLANSTATE" = "up" ]; then
		WIRELESS=""
	fi

	# M symbol if modem monitoring is on & modem present
	MODEMMON=""
	pgrep -f sxmo_modemmonitor.sh && MODEMMON=""

	# Battery pct
	PCT="$(cat /sys/class/power_supply/*-battery/capacity)"
	BATSTATUS="$(
		cat /sys/class/power_supply/*-battery/status |
		cut -c1
	)"
	if [ "$BATSTATUS" = "C" ]; then
		if [ "$PCT" -lt 20 ]; then
			BATSTATUS=""
		elif [ "$PCT" -lt 30 ]; then
			BATSTATUS=""
		elif [ "$PCT" -lt 40 ]; then
			BATSTATUS=""
		elif [ "$PCT" -lt 60 ]; then
			BATSTATUS=""
		elif [ "$PCT" -lt 80 ]; then
			BATSTATUS=""
		elif [ "$PCT" -lt 90 ]; then
			BATSTATUS=""
		else
			BATSTATUS=""
		fi
	else
		if [ "$PCT" -lt 10 ]; then
			BATSTATUS=""
		elif [ "$PCT" -lt 20 ]; then
			BATSTATUS=""
		elif [ "$PCT" -lt 30 ]; then
			BATSTATUS=""
		elif [ "$PCT" -lt 40 ]; then
			BATSTATUS=""
		elif [ "$PCT" -lt 50 ]; then
			BATSTATUS=""
		elif [ "$PCT" -lt 60 ]; then
			BATSTATUS=""
		elif [ "$PCT" -lt 70 ]; then
			BATSTATUS=""
		elif [ "$PCT" -lt 80 ]; then
			BATSTATUS=""
		elif [ "$PCT" -lt 90 ]; then
			BATSTATUS=""
		else
			BATSTATUS=""
		fi
	fi

	# Volume
	AUDIODEV="$(sxmo_audiocurrentdevice.sh)"
	AUDIOSYMBOL=$(echo "$AUDIODEV" | cut -c1)
	if [ "$AUDIOSYMBOL" = "L" ] || [ "$AUDIOSYMBOL" = "N" ]; then
		AUDIOSYMBOL="" #speakers or none, use no special symbol
	elif [ "$AUDIOSYMBOL" = "H" ]; then
		AUDIOSYMBOL=" "
	elif [ "$AUDIOSYMBOL" = "E" ]; then
		AUDIOSYMBOL=" " #earpiece
	fi
	VOL=0
	[ "$AUDIODEV" = "None" ] || VOL="$(
		amixer sget "$AUDIODEV" |
		grep -oE '([0-9]+)%' |
		tr -d ' %' |
		awk '{ s += $1; c++ } END { print s/c }'  |
		xargs printf %.0f
	)"
	if [ "$AUDIODEV" != "None" ]; then
		if [ "$VOL" -eq 0 ]; then
			VOLUMESYMBOL="ﱝ"
		elif [ "$VOL" -lt 25 ]; then
			VOLUMESYMBOL="奄"
		elif [ "$VOL" -gt 75 ]; then
			VOLUMESYMBOL="墳"
		else
			VOLUMESYMBOL="奔"
		fi
	fi
	# Time
	TIME="$(date +%R)"

	BAR="${CALLINFO} ${MODEMMON} ${WIRELESS} ${AUDIOSYMBOL}${VOLUMESYMBOL} ${BATSTATUS} ${TIME}"
	xsetroot -name "$BAR"
}

# E.g. on first boot justs to make sure the bar comes in quickly
update && sleep 1 && update && sleep 1

while :
do
	update
	sleep 30 & wait
done