-
Notifications
You must be signed in to change notification settings - Fork 0
/
bluetooth
executable file
·47 lines (43 loc) · 1.04 KB
/
bluetooth
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
get_from_file() {
dev=$1
name=
if [ ! -f /tmp/bt-devices.txt ]; then
touch /tmp/bt-devices.txt
echo ""
return
fi
for i in `cat /tmp/bt-devices.txt`; do
d=`echo $i | awk -F:: '{print $1}'`
if [ $d = $dev ]; then
name=`echo $i | awk -F:: '{print $2}'`
fi
done
echo "${name}"
}
store_file() {
dev=$1
name="${2}"
echo "$dev::${name}" >> /tmp/bt-devices.txt
}
connections=`hcitool con | sed -n 2p`
if [ ! -z "$connections" ]; then
# We have a connection, we want to get the name from a file if we've had
# it from there before because getting the name of the device connected
# is very slow and costly.
dev=`echo $connections | awk '{print $3}'`
name=`get_from_file $dev`
if [ -z "$name" ]; then
name=`hcitool name $dev | awk '{print $1}'`
if [ ! -z "${name}" ]; then
store_file $dev "${name}"
fi
fi
echo " $name"
echo " $name"
echo "#83AF40\n"
# echo "#859900\n"
else
echo ""
echo ""
fi