Skip to content

Commit b737385

Browse files
committed
improve: replace loop with a wildcard search and grep exclusion instead of if statements
* This simplifies the complexity of both action.sh and post-fs-data.sh while retaining identical behaviour Signed-off-by: TheSillyOk <priv.ld@proton.me>
1 parent 5b65b4a commit b737385

2 files changed

Lines changed: 12 additions & 41 deletions

File tree

action.sh

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,7 @@ mkdir -p "$SAVE_FOLDER"
1111
echo "Selecting the latest debug log file..."
1212
echo ""
1313

14-
index=0
15-
for f in "$SAVE_FOLDER"/*; do
16-
index=$((index + 1))
17-
LATEST=$(ls -t "$SAVE_FOLDER" | awk NR==$index)
18-
if [[ "$LATEST" == "" ]]; then
19-
break
20-
fi
21-
if [[ "$LATEST" != "DebugAssistant-Redacted.log" && "$LATEST" == "DebugAssistant"* ]]; then
22-
break
23-
fi
24-
LATEST=""
25-
done
26-
14+
LATEST=$(basename $(ls -t "$SAVE_FOLDER"/DebugAssistant* | grep -v "-Redacted" | head -n 1))
2715
if [[ "$LATEST" == "" ]]; then
2816
echo "No debug log found."
2917
exit 1
@@ -32,9 +20,6 @@ fi
3220
echo "Latest debug log selected: $LATEST"
3321

3422
NEW_LOG="$SAVE_FOLDER/DebugAssistant-Redacted.log"
35-
if [ -f "$NEW_LOG" ]; then
36-
rm "$NEW_LOG"
37-
fi
3823

3924
echo ""
4025
echo "Redacting sensitive information..."
@@ -78,5 +63,5 @@ echo ""
7863
echo "Redacted logs in $NEW_LOG"
7964
echo ""
8065

81-
echo "Copied redacted log to /sdcard/Download..."
8266
cp "$NEW_LOG" /sdcard/Download
67+
echo "Copied redacted log to /sdcard/Download..."

post-fs-data.sh

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,15 @@ function watch_logcat() {
2121
while [ ! ];do logcat;sleep 1;done > "$file_path" &
2222
}
2323

24-
FILES=$(ls "$SAVE_FOLDER" | grep 'DebugAssistant')
25-
if [[ "$FILES" != "" ]]; then
26-
index=1
27-
for f in "$SAVE_FOLDER"/*; do
28-
LATEST=$(ls -t "$SAVE_FOLDER" | awk NR==$index)
29-
if [[ "$LATEST" == "DebugAssistant.log" ]]; then
30-
prepare_file "-2"
31-
watch_logcat "-2"
32-
break
33-
fi
34-
if [[ "$LATEST" == "DebugAssistant-2.log" ]]; then
35-
prepare_file "-3"
36-
watch_logcat "-3"
37-
break
38-
fi
39-
if [[ "$LATEST" == "DebugAssistant-3.log" ]]; then
40-
prepare_file ""
41-
watch_logcat ""
42-
break
43-
fi
44-
index=$((index + 1))
45-
done
24+
25+
LATEST=$(basename $(ls -t "$SAVE_FOLDER"/DebugAssistant*.log | grep -v "Redacted" | head -n 1))
26+
if [[ "$LATEST" == "DebugAssistant.log" ]]; then
27+
SUFFIX="-2"
28+
elif [[ "$LATEST" == "DebugAssistant-2.log" ]]; then
29+
SUFFIX="-3"
4630
else
47-
prepare_file ""
48-
watch_logcat ""
31+
SUFFIX=""
4932
fi
33+
34+
prepare_file "$SUFFIX"
35+
watch_logcat "$SUFFIX"

0 commit comments

Comments
 (0)