Skip to content

Commit f3a5ddf

Browse files
committed
General fixes & optimizations
1 parent 1df57e7 commit f3a5ddf

9 files changed

+73
-81
lines changed

install/acc.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ exxit() {
170170
local exitCode=$?
171171
set +eux
172172
! ${noEcho:-false} && ${verbose:-true} && echo
173-
tt "$exitCode" "[05689]" || {
174-
tt "$exitCode" "[127]|10" && logf --export
173+
[[ "$exitCode" = [05689] ]] || {
174+
eq "$exitCode" "[127]|10" && logf --export
175175
echo
176176
}
177177
cd /
@@ -263,15 +263,15 @@ defaultConfig=$execDir/default-config.txt
263263
. $execDir/logf.sh
264264
. $execDir/misc-functions.sh
265265

266-
if [ "${1:-y}" = -x ] || tt "${2-}" "p|parse"; then
266+
if [ "${1:-y}" = -x ] || eq "${2-}" "p|parse"; then
267267
log=/sdcard/Download/acc-${device}.log
268268
[ $1 != -x ] || shift
269269
else
270270
log=$TMPDIR/acc-${device}.log
271271
fi
272272

273273
# verbose
274-
if ${verbose:-true} && ! tt "${1-}" "-l*|--log*|-w*|--watch*"; then
274+
if ${verbose:-true} && ! eq "${1-}" "-l*|--log*|-w*|--watch*"; then
275275
[ -z "${LINENO-}" ] || export PS4='$LINENO: '
276276
touch $log
277277
[ $(du -k $log | cut -f 1) -ge 256 ] && : > $log
@@ -287,7 +287,7 @@ accVerCode=$(get_prop versionCode $execDir/module.prop)
287287
unset -f get_prop
288288

289289
misc_stuff "${1-}"
290-
! tt "${1-}" "*/*" || shift
290+
[[ "${1-}" != */* ]] || shift
291291

292292
. $config
293293

@@ -309,7 +309,7 @@ grep -q .. $execDir/translations/$language/README.html 2>/dev/null \
309309
# aliases/shortcuts
310310
# daemon_ctrl status (acc -D|--daemon): "accd,"
311311
# daemon_ctrl stop (acc -D|--daemon stop): "accd."
312-
! tt "$0" "*accd*" || {
312+
[[ "$0" != *accd* ]] || {
313313
case $0 in
314314
*accd.) daemon_ctrl stop;;
315315
*) daemon_ctrl;;
@@ -332,7 +332,7 @@ case "${1-}" in
332332
echo ""
333333
;;
334334

335-
-b|--rollback)
335+
-b*|--rollback*)
336336
rollback "${*-}"
337337
;;
338338

@@ -568,7 +568,7 @@ case "${1-}" in
568568
grep '^chargingSwitch=' $config; } | tee $logF
569569

570570
if [ -z "${2-}" ]; then
571-
! tt "${1-}" "p|parse" || parsed=$TMPDIR/.parsed
571+
! eq "${1-}" "p|parse" || parsed=$TMPDIR/.parsed
572572
[ -z "$parsed" ] || {
573573
_parsed=$dataDir/logs/parsed.log
574574
if parse_switches > $parsed; then

install/acca.sh

+15-17
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ daemon_ctrl() {
2525
}
2626

2727

28-
# extended test
29-
tt() {
28+
# condensed "case...esac"
29+
eq() {
3030
eval "case \"$1\" in
3131
$2) return 0;;
3232
esac"
@@ -50,13 +50,11 @@ cd /sys/class/power_supply/
5050
mkdir -p $dataDir
5151

5252
# custom config path
53-
case "${1-}" in
54-
*/*)
55-
[ -f $1 ] || cp $config $1
56-
config=$1
57-
shift
58-
;;
59-
esac
53+
! eq "${1-}" "*/*" || {
54+
[ -f $1 ] || cp $config $1
55+
config=$1
56+
shift
57+
}
6058

6159

6260
case "$@" in
@@ -94,15 +92,15 @@ case "$@" in
9492

9593
export "$@"
9694

97-
# [ .${mcc-${max_charging_current-x}} = .x ] || {
98-
# . $execDir/set-ch-curr.sh
99-
# set_ch_curr ${mcc:-${max_charging_current:--}} || :
100-
# }
95+
[ .${mcc-${max_charging_current-x}} = .x ] || {
96+
. $execDir/set-ch-curr.sh
97+
set_ch_curr ${mcc:-${max_charging_current:--}} || :
98+
}
10199

102-
# [ ".${mcv-${max_charging_voltage-x}}" = .x ] || {
103-
# . $execDir/set-ch-volt.sh
104-
# set_ch_volt "${mcv:-${max_charging_voltage:--}}" || :
105-
# }
100+
[ ".${mcv-${max_charging_voltage-x}}" = .x ] || {
101+
. $execDir/set-ch-volt.sh
102+
set_ch_volt "${mcv:-${max_charging_voltage:--}}" || :
103+
}
106104

107105
. $execDir/write-config.sh
108106
exit 0

install/accd.sh

+32-32
Original file line numberDiff line numberDiff line change
@@ -19,66 +19,66 @@ if ! $init; then
1919

2020

2121
_ge_cooldown_cap() {
22-
if t ${capacity[1]} -gt 3000; then
23-
t $(volt_now) -ge ${capacity[1]}
22+
if [ ${capacity[1]} -gt 3000 ]; then
23+
[ $(volt_now) -ge ${capacity[1]} ]
2424
else
25-
t $(cat $battCapacity) -ge ${capacity[1]}
25+
[ $(cat $battCapacity) -ge ${capacity[1]} ]
2626
fi
2727
}
2828

2929

3030
_ge_pause_cap() {
31-
if t ${capacity[3]} -gt 3000; then
32-
t $(volt_now) -ge ${capacity[3]}
31+
if [ ${capacity[3]} -gt 3000 ]; then
32+
[ $(volt_now) -ge ${capacity[3]} ]
3333
else
34-
t $(cat $battCapacity) -ge ${capacity[3]}
34+
[ $(cat $battCapacity) -ge ${capacity[3]} ]
3535
fi
3636
}
3737

3838

3939
_le_pause_cap() {
40-
if t ${capacity[3]} -gt 3000; then
41-
t $(volt_now) -le ${capacity[3]}
40+
if [ ${capacity[3]} -gt 3000 ]; then
41+
[ $(volt_now) -le ${capacity[3]} ]
4242
else
43-
t $(cat $battCapacity) -le ${capacity[3]}
43+
[ $(cat $battCapacity) -le ${capacity[3]} ]
4444
fi
4545
}
4646

4747

4848
_lt_pause_cap() {
49-
if t ${capacity[3]} -gt 3000; then
50-
t $(volt_now) -lt ${capacity[3]}
49+
if [ ${capacity[3]} -gt 3000 ]; then
50+
[ $(volt_now) -lt ${capacity[3]} ]
5151
else
52-
t $(cat $battCapacity) -lt ${capacity[3]}
52+
[ $(cat $battCapacity) -lt ${capacity[3]} ]
5353
fi
5454
}
5555

5656

5757
_gt_resume_cap() {
58-
if t ${capacity[2]} -gt 3000; then
59-
t $(volt_now) -gt ${capacity[2]}
58+
if [ ${capacity[2]} -gt 3000 ]; then
59+
[ $(volt_now) -gt ${capacity[2]} ]
6060
else
61-
t $(cat $battCapacity) -gt ${capacity[2]}
61+
[ $(cat $battCapacity) -gt ${capacity[2]} ]
6262
fi
6363
}
6464

6565

6666
_le_resume_cap() {
6767
if $mtReached && _lt_pause_cap; then
6868
return 0
69-
elif t ${capacity[2]} -gt 3000; then
70-
t $(volt_now) -le ${capacity[2]}
69+
elif [ ${capacity[2]} -gt 3000 ]; then
70+
[ $(volt_now) -le ${capacity[2]} ]
7171
else
72-
t $(cat $battCapacity) -le ${capacity[2]}
72+
[ $(cat $battCapacity) -le ${capacity[2]} ]
7373
fi
7474
}
7575

7676

7777
_le_shutdown_cap() {
78-
if t ${capacity[0]} -gt 3000; then
79-
t $(volt_now) -le ${capacity[0]}
78+
if [ ${capacity[0]} -gt 3000 ]; then
79+
[ $(volt_now) -le ${capacity[0]} ]
8080
else
81-
t $(cat $battCapacity) -le ${capacity[0]}
81+
[ $(cat $battCapacity) -le ${capacity[0]} ]
8282
fi
8383
}
8484

@@ -112,7 +112,7 @@ if ! $init; then
112112
apply_on_plug default
113113
tempLevel=0
114114
enable_charging
115-
if tt "$exitCode" "[127]"; then
115+
if [[ "$exitCode" = [127] ]]; then
116116
. $execDir/logf.sh
117117
logf --export
118118
notif "⚠️ Daemon stopped with exit code $exitCode! Run \"acc -l tail\" to see the last 10 lines of the log file."
@@ -137,15 +137,15 @@ if ! $init; then
137137
else
138138
isCharging=true
139139
# [auto mode] change the charging switch if charging has not been enabled by acc (if behavior repeats 3 times)
140-
if $chDisabledByAcc && [ -n "${chargingSwitch[0]-}" ] && ! tt "${chargingSwitch[*]}" "*--" \
140+
if $chDisabledByAcc && [ -n "${chargingSwitch[0]-}" ] && [[ "${chargingSwitch[*]}" != *\ -- ]] \
141141
&& sleep ${loopDelay[1]} && { ! not_charging || { isCharging=false; false; }; }
142142
then
143143
if [ $unsolicitedResumes -ge 3 ]; then
144144
if grep -q "^${chargingSwitch[*]}$" $TMPDIR/ch-switches; then
145145
sed -i "\|^${chargingSwitch[*]}$|d" $TMPDIR/ch-switches
146146
echo "${chargingSwitch[*]}" >> $TMPDIR/ch-switches
147147
fi
148-
$TMPDIR/acca --set charging_switch=
148+
$TMPDIR/acca $config --set charging_switch=
149149
chargingSwitch=()
150150
unsolicitedResumes=0
151151
else
@@ -185,10 +185,10 @@ if ! $init; then
185185
if [ -f $TMPDIR/.ch-curr-read ]; then
186186
# set charging current control files, as needed
187187
if [ -n "${maxChargingCurrent[0]-}" ] \
188-
&& { [ -z "${maxChargingCurrent[1]-}" ] || tt "${maxChargingCurrent[1]-}" "-*"; } \
188+
&& { [ -z "${maxChargingCurrent[1]-}" ] || [[ "${maxChargingCurrent[1]-}" = -* ]]; } \
189189
&& grep -q / $TMPDIR/ch-curr-ctrl-files 2>/dev/null
190190
then
191-
$TMPDIR/acca --set max_charging_current=${maxChargingCurrent[0]}
191+
$TMPDIR/acca $config --set max_charging_current=${maxChargingCurrent[0]}
192192
fi
193193
else
194194
# parse charging current ctrl files
@@ -197,10 +197,10 @@ if ! $init; then
197197

198198
# set charging voltage control files, as needed
199199
if [ -n "${maxChargingVoltage[0]-}" ] \
200-
&& { [ -z "${maxChargingVoltage[1]-}" ] || tt "${maxChargingVoltage[1]-}" "-*"; } \
200+
&& { [ -z "${maxChargingVoltage[1]-}" ] || [[ "${maxChargingCurrent[1]-}" = -* ]]; } \
201201
&& grep -q / $TMPDIR/ch-volt-ctrl-files 2>/dev/null
202202
then
203-
$TMPDIR/acca --set max_charging_voltage=${maxChargingVoltage[0]}
203+
$TMPDIR/acca $config --set max_charging_voltage=${maxChargingVoltage[0]}
204204
fi
205205

206206
$cooldown || {
@@ -369,12 +369,12 @@ if ! $init; then
369369
if [ ${capacity[0]} -ge 1 ]; then
370370
# warnings
371371
! $shutdownWarnings || {
372-
if t ${capacity[0]} -gt 3000; then
373-
! t $(grep -o '^..' $voltNow) -eq $(( ${capacity[0]%??} + 1 )) \
372+
if [ ${capacity[0]} -gt 3000 ]; then
373+
! [ $(grep -o '^..' $voltNow) -eq $(( ${capacity[0]%??} + 1 )) ] \
374374
|| ! notif "⚠️ WARNING: ~100mV to auto shutdown, plug the charger!" \
375375
|| sleep ${loopDelay[1]}
376376
else
377-
! t $(cat $battCapacity) -eq $(( ${capacity[0]} + 5 )) \
377+
! [ $(cat $battCapacity) -eq $(( ${capacity[0]} + 5 )) ] \
378378
|| ! notif "⚠️ WARNING: 5% to auto shutdown, plug the charger!" \
379379
|| sleep ${loopDelay[1]}
380380
fi
@@ -419,7 +419,7 @@ if ! $init; then
419419
local curr=
420420
. $config
421421
while [ -z "${dischargePolarity-}" ] && [ $currFile != $TMPDIR/.dummy-curr ] && $battStatusWorkaround; do
422-
cmd="$TMPDIR/acca --set discharge_polarity="
422+
cmd="$TMPDIR/acca $config --set discharge_polarity="
423423
curr=$(cat $currFile)
424424
if online; then
425425
if [ $(cat $battStatus) = Charging ] && [ ${curr#-} -gt $idleThreshold ]; then

install/batt-interface.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ idle_discharging() {
77
+) [ $curNow -ge 0 ] && _status=Discharging || _status=Charging;;
88
-) [ $curNow -lt 0 ] && _status=Discharging || _status=Charging;;
99
*) [ $curThen = null ] || {
10-
tt "$curThen,$curNow" "-*,[0-9]*|[0-9]*,-*" && _status=Discharging || _status=Charging
10+
eq "$curThen,$curNow" "-*,[0-9]*|[0-9]*,-*" && _status=Discharging || _status=Charging
1111
};;
1212
esac
1313
}
@@ -23,7 +23,7 @@ not_charging() {
2323
local battStatusOverride="${battStatusOverride-}"
2424
local battStatusWorkaround=${battStatusWorkaround-}
2525

26-
tt "${chargingSwitch[$*]-}" "*\ --" || battStatusOverride=
26+
[[ "${chargingSwitch[$*]-}" = *\ -- ]] || battStatusOverride=
2727

2828
case "$currFile" in
2929
*/current_now|*/?attery?verage?urrent) [ ${ampFactor:-$ampFactor_} -eq 1000 ] || idleThreshold=${idleThreshold}000;;
@@ -108,7 +108,7 @@ status() {
108108
_status=$(read_status)
109109

110110
if [ -n "${battStatusOverride-}" ]; then
111-
if tt "$battStatusOverride" "Discharging|Idle"; then
111+
if eq "$battStatusOverride" "Discharging|Idle"; then
112112
[ $(cat ${chargingSwitch[0]}) != ${chargingSwitch[2]} ] || _status=$battStatusOverride
113113
else
114114
_status=$(set -eu; eval '$battStatusOverride') || :

install/logf.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ logf() {
22

33
local date=$(date +%Y-%m-%d_%H:%M:%S)
44

5-
if tt "${1:-x}" "-*e*"; then
5+
if [[ "${1:-x}" = -*e* ]]; then
66

77
mkdir -p $dataDir/logs
88

install/misc-functions.sh

+10-16
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ apply_on_boot() {
1111

1212
[ ${2:-x} != force ] || force=true
1313

14-
! tt "${applyOnBoot[*]-}${maxChargingVoltage[*]-}" "*--exit*" || exitCmd=true
14+
[[ "${applyOnBoot[*]-}${maxChargingVoltage[*]-}" != *--exit* ]] || exitCmd=true
1515

1616
for entry in ${applyOnBoot[@]-} ${maxChargingVoltage[@]-}; do
1717
set -- ${entry//::/ }
@@ -130,9 +130,9 @@ disable_charging() {
130130

131131
# not_charging || {
132132

133-
! tt "${chargingSwitch[*]-}" "*--" || autoMode=false
133+
[[ "${chargingSwitch[*]-}" != *\ -- ]] || autoMode=false
134134

135-
if tt "${chargingSwitch[0]-}" "*/*"; then
135+
if [[ "${chargingSwitch[0]-}" = */* ]]; then
136136
if [ -f ${chargingSwitch[0]} ]; then
137137
if ! { flip_sw off && not_charging; }; then
138138
$isAccd || print_switch_fails "${chargingSwitch[@]-}"
@@ -312,7 +312,7 @@ invalid_switch() {
312312

313313
is_android() {
314314
[ ! -d /data/usbmsc_mnt/ ] && [ -x /system/bin/dumpsys ] \
315-
&& ! tt "$(readlink -f $execDir)" "*com.termux*" \
315+
&& [[ "$(readlink -f $execDir)" != *com.termux* ]] \
316316
&& pgrep -f zygote >/dev/null
317317
}
318318

@@ -334,12 +334,10 @@ misc_stuff() {
334334
[ -f $config ] || cat $execDir/default-config.txt > $config
335335

336336
# custom config path
337-
case "${1-}" in
338-
*/*)
339-
[ -f $1 ] || cp $config $1
340-
config=$1
341-
;;
342-
esac
337+
! eq "${1-}" "*/*" || {
338+
[ -f $1 ] || cp $config $1
339+
config=$1
340+
}
343341
unset -f misc_stuff
344342
}
345343

@@ -371,12 +369,8 @@ print_wait_plug() {
371369
}
372370

373371

374-
# test
375-
t() { test "$@"; }
376-
377-
378-
# extended test
379-
tt() {
372+
# condensed "case...esac"
373+
eq() {
380374
eval "case \"$1\" in
381375
$2) return 0;;
382376
esac"

install/set-prop.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ set_prop() {
116116
*)
117117
if [ -f "${1:-//}" ]; then
118118
cat "$1" > $config
119-
$TMPDIR/acca --set dummy=
119+
$TMPDIR/acca $config --set dummy=
120120
else
121121
. $execDir/print-config.sh | more
122122
return 0

0 commit comments

Comments
 (0)