Skip to content

Commit 917de84

Browse files
committed
Merge pull request #4 from crushedice2000/patch-3
Fix #1 progressbar
2 parents f2022d8 + f0628df commit 917de84

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

load

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,34 @@
33
mac_address="$1"
44
file="$2"
55

6+
function progress_bar() {
7+
progress_character='='
8+
percent_bar="$(head -c "$(($1/5))" < /dev/zero | tr '\0' $progress_character)"
9+
percent_bar="${percent_bar}$(printf "%$((20-($1/5)))s")"
10+
printf "\rLoading... [%s] (%s%%)" "$percent_bar" "$1"
11+
}
12+
613
function load() {
14+
counter=0
15+
lines=$(wc -l <$file)
16+
progress_bar 0
717
while read line; do
818
line=$(printf '%s\r' "$line" | xxd -p | tr -d '\n')
9-
gatttool -i hci0 -b "$mac_address" --char-write-req -a 0x0031 -n $line
19+
gatttool -i hci0 \
20+
-n $line \
21+
-a 0x0031 \
22+
-b "$mac_address" \
23+
--char-write-req 1>/dev/null
24+
((counter++))
25+
percentage="$(bc <<< "scale=2; (${counter}/${lines})*100")"
26+
progress_bar "${percentage%.*}"
1027
done < $file
28+
printf "\n"
1129
}
1230

1331
if [[ ! "$mac_address" =~ ^([a-fA-F0-9]{2}:){5}[a-zA-Z0-9]{2}$ ]]; then
1432
error="Wrong MAC address! Example: AA:BB:CC:DD:EE:FF"
15-
elif [[ ! -r $file && -f $file ]]; then
33+
elif ! [[ -r $file && -f $file ]]; then
1634
error="No such file!"
1735
else
1836
load

0 commit comments

Comments
 (0)