Skip to content

Instantly share code, notes, and snippets.

@vilhalmer
Created July 11, 2018 01:13
Show Gist options
  • Save vilhalmer/2b96ad656623603ebb86dbccd1a85b5a to your computer and use it in GitHub Desktop.
Save vilhalmer/2b96ad656623603ebb86dbccd1a85b5a to your computer and use it in GitHub Desktop.
bt: Wrapper for `bluetoothctl` that allows shortest-prefix for device name and command
#!/bin/env bash
device=$(bluetoothctl paired-devices | grep -iE "$1" | cut -d' ' -f2)
if [[ -n $2 ]]; then
command=$(bluetoothctl help | cut -d' ' -f1 | grep -iE "$2" | head -n1 | perl -pe 's/\e([^\[\]]|\[.*?[a-zA-Z]|\].*?\a)//g')
else
command="connect"
fi
echo "Command: bluetoothctl $command $device"
bluetoothctl "$command" "$device"
@vilhalmer
Copy link
Author

Assuming device named "Device":
bt dev connects
bt dev discon disconnects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment