speed up in code execution, less copied code

This commit is contained in:
Alexander Bocken 2021-01-01 22:47:16 +01:00
parent 115a89b5c6
commit 2726f0c0fd
Signed by: Alexander
GPG Key ID: 1D237BE83F9B05E8

15
bt
View File

@ -26,8 +26,11 @@ done
power(){ power(){
powerstatus="$( bluetoothctl show | grep Powered | awk '{print $2}' )" powerstatus="$( bluetoothctl show | grep Powered | awk '{print $2}' )"
[ "$powerstatus" = "no" ] && [ "$1" = on ] && bluetoothctl power on if [ "$powerstatus" = "no" ]; then
[ "$powerstatus" = "yes" ] && [ "$1" = off ] && bluetoothctl power off [ "$1" = on ] && bluetoothctl power on
elif [ "$powerstatus" = "yes" ]; then
[ "$1" = off ] && bluetoothctl power off
fi
} }
scan(){ scan(){
@ -117,12 +120,8 @@ pair(){
start_scan="$(cat /tmp/bt_start_scan$$)" start_scan="$(cat /tmp/bt_start_scan$$)"
if [ $((( "$(date +'%s')" - "$start_scan" ))) -lt $SCAN_PERIOD ]; then if [ $((( "$(date +'%s')" - "$start_scan" ))) -lt $SCAN_PERIOD ]; then
sleep_period="$((( "$SCAN_PERIOD" - "$( date +'%s')" + "$start_scan" )))" sleep_period="$((( "$SCAN_PERIOD" - "$( date +'%s')" + "$start_scan" )))"
if [ "$sleep_period" -eq 1 ]; then [ "$sleep_period" -gt 1 ] && plural="s"
notify-send "Bluetooth" "Searching for devices, please wait 1 second" notify-send "Bluetooth" "Searching for devices, please wait $sleep_period second$plural"
else
notify-send "Bluetooth" "Searching for devices, please wait $sleep_period seconds"
fi
sleep "$sleep_period" sleep "$sleep_period"
fi fi
all_devices="$( bluetoothctl devices )" all_devices="$( bluetoothctl devices )"