Skip to content

Commit

Permalink
Remove unnecessary variable usage
Browse files Browse the repository at this point in the history
We don't need to use device_list variable while devices variable can be directly used
  • Loading branch information
jeevithakannan2 committed Nov 20, 2024
1 parent c73fd51 commit b1b7ce0
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions core/tabs/utils/bluetooth-control.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,20 @@ prompt_for_mac() {
fi

# Display devices with numbers
device_list="$devices"
i=1
echo "$device_list" | while IFS= read -r device; do
echo "$devices" | while IFS= read -r device; do
printf "%d. %s\n" "$i" "$device"
i=$((i + 1))
done
printf "%b\n" "0. Exit to main menu"
printf "%b" "$prompt_msg"
read -r choice

count=$(printf "%b" "$device_list" | wc -l)
count=$(printf "%b" "$devices" | wc -l)
count=$((count + 1))

if echo "$choice" | grep -qE '^[0-9]+$' && [ -n "$choice" ] && [ "$choice" -le "$count" ] && [ "$choice" -gt 0 ]; then
device=$(echo "$device_list" | sed -n "${choice}p")
device=$(echo "$devices" | sed -n "${choice}p")
mac=$(echo "$device" | awk '{print $2}')
if bluetoothctl info "$mac" >/dev/null 2>&1; then
if bluetoothctl "$command" "$mac"; then
Expand All @@ -105,12 +104,10 @@ prompt_for_mac() {
else
printf "%b\n" "${RED}$failure_msg${RC}"
read -r _

fi
else
printf "%b\n" "${RED}Invalid MAC address. Please try again.${RC}"
read -r _

fi
elif [ "$choice" -eq 0 ]; then
return
Expand Down

0 comments on commit b1b7ce0

Please sign in to comment.