Shell scripts minimizing machine time, maximizing tao time.

git clone git://watertao.xyz/programs/tao_shells.git

tao_bluetooth_connect.sh (886B)


      1 #!/bin/sh
      2 cmdf(){ command -v $1 >/dev/null 2>&1; }
      3 ! cmdf "bluetoothctl" && \
      4 	printf "Please install bluetoothctl to use me.\n" && exit 1
      5 
      6 # dmenu command
      7 if [ -z "$DMENU" ]
      8 then
      9 	a="dmenu sxmo_dmenu.sh bemenu rofi"
     10 	for i in $a; do cmdf "$i" && export DMENU="$i" && break; done
     11 fi
     12 
     13 # optional configs
     14 if [ -z "$DMENU_OPTS" ]
     15 then
     16 	a="$HOME/.config/tao/tao_dmenu.conf" && [ -f "$a" ] && \
     17 		DMENU_OPTS=$(<"$a" sed -n '1p' | tr -d "\n")
     18 	export DMENU_OPTS="${DMENU_OPTS:-""}"
     19 fi
     20 
     21 a=$(bluetoothctl devices | awk '{printf("%-10s %s\n", $3, $2)}' | \
     22 	$DMENU -i $DMENU_OPTS -p "[ connect to bluetooth device ]")
     23 
     24 [ -z "$a" ] && exit 0
     25 
     26 sleep 1
     27 a="${a##* }"
     28 printf "Connecting to %s\n" "$a"
     29 /usr/bin/bluetoothctl -t 1 discoverable on
     30 /usr/bin/bluetoothctl -t 10 --monitor scan on
     31 /usr/bin/bluetoothctl pair $a
     32 sleep 2
     33 /usr/bin/bluetoothctl trust $a
     34 sleep 2
     35 /usr/bin/bluetoothctl connect $a