From 35d57c60a29f4754e98cc7508f5c346bb50f7361 Mon Sep 17 00:00:00 2001 From: Odweta Date: Sun, 21 Dec 2025 23:45:16 +0100 Subject: [PATCH] initial commit --- Makefile | 4 ++++ README.md | 5 +++++ obt.sh | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 Makefile create mode 100644 README.md create mode 100644 obt.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a732661 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +install: + mkdir -p $(HOME)/.local/bin/ + cp obt.sh $(HOME)/.local/bin/obt + chmod 744 $(HOME)/.local/bin/obt diff --git a/README.md b/README.md new file mode 100644 index 0000000..83292ab --- /dev/null +++ b/README.md @@ -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. diff --git a/obt.sh b/obt.sh new file mode 100644 index 0000000..9a512b9 --- /dev/null +++ b/obt.sh @@ -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 # 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