initial commit

This commit is contained in:
Odweta
2025-12-21 23:45:16 +01:00
commit 35d57c60a2
3 changed files with 64 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
install:
mkdir -p $(HOME)/.local/bin/
cp obt.sh $(HOME)/.local/bin/obt
chmod 744 $(HOME)/.local/bin/obt
+5
View File
@@ -0,0 +1,5 @@
# My Bluetooth helper program
It just autoconnects to a pre-selected device and allows to disconnect or connect again.
Address to be used is defined in ~/.config/obt.conf.
+55
View File
@@ -0,0 +1,55 @@
#!/bin/bash
CFG="$HOME/.config/obt.conf"
# ensure config file exists
mkdir -p "$(dirname "$CFG")"
[[ -e $CFG ]] || touch "$CFG"
read -r ADDR < "$CFG"
init() {
# save address if not set and argument is not a command
if [[ -z $ADDR && $1 != c && $1 != d ]]; then
ADDR=$1
echo "$ADDR" > "$CFG"
fi
echo "trusting..."
bluetoothctl trust "$ADDR"
echo "pairing..."
bluetoothctl pair "$ADDR"
echo "done!"
}
connect() {
bluetoothctl connect "$ADDR"
}
disconnect() {
bluetoothctl disconnect "$ADDR"
}
usage() {
echo "usage:"
echo " $0 <BT_ADDRESS> # pair + trust + save"
echo " $0 c # connect"
echo " $0 d # disconnect"
exit 1
}
[[ $# -eq 0 ]] && usage
case "$1" in
c)
[[ -z $ADDR ]] && echo "no saved address" && exit 1
connect
;;
d)
[[ -z $ADDR ]] && echo "no saved address" && exit 1
disconnect
;;
*)
init "$1"
;;
esac