summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/.bin/add-bookmark.sh36
-rwxr-xr-xbin/.bin/bluetooth.sh140
-rwxr-xr-xbin/.bin/new-episode35
-rwxr-xr-xbin/.bin/open-bookmark.sh23
-rwxr-xr-xbin/.bin/power.sh22
5 files changed, 221 insertions, 35 deletions
diff --git a/bin/.bin/add-bookmark.sh b/bin/.bin/add-bookmark.sh
new file mode 100755
index 0000000..9a8ab6b
--- /dev/null
+++ b/bin/.bin/add-bookmark.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+BOOKMARKS_FILE="$DOTFILES_REPO/bookmarks.txt"
+
+mkdir -p "$(dirname "$BOOKMARKS_FILE")"
+touch "$BOOKMARKS_FILE"
+
+xdotool key --delay 50 ctrl+l ctrl+c Escape
+
+sleep 0.15
+
+URL=$(xclip -selection clipboard -o)
+
+if [[ "$URL" =~ ^https?:// ]]; then
+ NAME=$(zenity --entry \
+ --title="Add Bookmark" \
+ --text="Enter a name for this bookmark:" \
+ --entry-text="" 2>/dev/null)
+
+ if [ -z "$NAME" ]; then
+ notify-send "Bookmark Cancelled" "No name was provided."
+ exit 0
+ fi
+
+ CLEAN_NAME=$(echo "$NAME" | tr '|' '-')
+
+ if ! grep -q "|$URL$" "$BOOKMARKS_FILE"; then
+ echo "$CLEAN_NAME|$URL" >>"$BOOKMARKS_FILE"
+ notify-send "Bookmark Saved" "$CLEAN_NAME\n$URL"
+ else
+ notify-send "Bookmark" "This exact URL already exists!"
+ fi
+else
+ notify-send "Bookmark Error" "Clipboard did not contain a valid URL."
+fi
diff --git a/bin/.bin/bluetooth.sh b/bin/.bin/bluetooth.sh
new file mode 100755
index 0000000..5ae5281
--- /dev/null
+++ b/bin/.bin/bluetooth.sh
@@ -0,0 +1,140 @@
+#!/usr/bin/env bash
+set -uo pipefail # Keep -e off so our self-healing logic can handle error codes safely
+
+# Define the Rofi menu layout.
+declare -a order=(
+ "⚡ Power On Bluetooth"
+ "🛑 Power Off Bluetooth"
+ "🔌 Disconnect All Devices"
+ "---"
+ "Speaker"
+ "Earphones"
+ "Earphones Left"
+ "Living Room"
+)
+
+# Map profiles to hardware MAC addresses.
+declare -A devices
+devices[Speaker]="A0:E9:DB:0E:43:79"
+devices[Earphones]="98:52:3D:F2:6E:3E"
+devices["Earphones Left"]="98:52:3D:F2:36:78"
+devices["Living Room"]="42:46:9F:D0:2C:53"
+
+# Prompt User via Rofi.
+MENU_OPTIONS=$(printf "%s\n" "${order[@]}")
+SELECTION=$(echo "$MENU_OPTIONS" | rofi -dmenu -p "Bluetooth Menu:")
+
+# Exit gracefully if the user hits Escape.
+if [ -z "$SELECTION" ] || [ "$SELECTION" = "---" ]; then
+ exit 0
+fi
+
+if [ "$SELECTION" = "⚡ Power On Bluetooth" ]; then
+ notify-send "BT" "Powering adapter on..."
+ bluetoothctl power on
+ exit 0
+fi
+
+if [ "$SELECTION" = "🛑 Power Off Bluetooth" ]; then
+ notify-send "BT" "Powering adapter off..."
+ bluetoothctl power off
+ exit 0
+fi
+
+if [ "$SELECTION" = "🔌 Disconnect All Devices" ]; then
+ notify-send "BT" "Clearing all active connections..."
+ for name in "${!devices[@]}"; do
+ bluetoothctl disconnect "${devices[$name]}" >/dev/null 2>&1 || true
+ done
+ notify-send "BT" "All devices disconnected."
+ exit 0
+fi
+
+if [ -z "${devices[$SELECTION]:-}" ]; then
+ notify-send "ERROR" "Invalid choice: $SELECTION"
+ exit 1
+fi
+
+TARGET_MAC="${devices[$SELECTION]}"
+
+# Ensure controller is actually powered up before trying to connect.
+if ! bluetoothctl show | grep -q "Powered: yes"; then
+ notify-send "BT" "Waking up Bluetooth adapter..."
+ bluetoothctl power on
+ sleep 2
+fi
+
+# Force controller runtime options to accept incoming passthroughs.
+bluetoothctl pairable on >/dev/null 2>&1 || true
+bluetoothctl discoverable on >/dev/null 2>&1 || true
+
+# Disconnect existing targets to free up the system audio pipelines.
+for name in "${!devices[@]}"; do
+ bluetoothctl disconnect "${devices[$name]}" >/dev/null 2>&1 || true
+done
+
+# Query the machine's local hardware database cache.
+DEVICE_CHECK=$(bluetoothctl info "$TARGET_MAC" 2>&1 || true)
+
+if echo "$DEVICE_CHECK" | grep -q "not available"; then
+ notify-send "BT: Provisioning" "Device missing from system cache. Probing airwaves..."
+
+ # Run a targeted background scan pass to register device metadata.
+ bluetoothctl --timeout 5 scan on >/dev/null 2>&1 &
+ SCAN_PID=$!
+ sleep 4
+ kill "$SCAN_PID" 2>/dev/null || true
+ wait "$SCAN_PID" 2>/dev/null || true
+ sleep 1
+
+ notify-send "BT: Provisioning" "Exchanging encryption keys..."
+ bluetoothctl pair "$TARGET_MAC"
+ bluetoothctl trust "$TARGET_MAC"
+fi
+
+# Attempt targeted connection sequence.
+notify-send "BT Switch" "Routing audio to $SELECTION..."
+CONNECT_OUT=$(bluetoothctl connect "$TARGET_MAC" 2>&1 || true)
+echo "$CONNECT_OUT"
+
+if echo "$CONNECT_OUT" | grep -q "Connection successful"; then
+ bluetoothctl trust "$TARGET_MAC" >/dev/null 2>&1 || true
+
+ # WirePlumber Sinks Syncing Engine.
+ CLEAN_MAC="${TARGET_MAC//:/_}"
+ SINK_NAME=$(wpctl status | grep -o "bluez_output\.[^\ ]*${CLEAN_MAC}[^\ ]*" | head -n 1 || true)
+
+ if [ ! -z "$SINK_NAME" ]; then
+ wpctl set-default "$SINK_NAME"
+ # Set a safe volumne just in case we connect to earphones.
+ wpctl set-volume "$SINK_NAME" 0.10
+ fi
+
+ notify-send "BT Switch" "$SELECTION connected successfully!"
+
+# Handle key synchronization issues seamlessly....
+elif echo "$CONNECT_OUT" | grep -q "br-connection-key-missing"; then
+ notify-send "BT Error" "Key mismatch! Purging and re-pairing..."
+
+ bluetoothctl remove "$TARGET_MAC" >/dev/null 2>&1 || true
+ sleep 1
+
+ bluetoothctl --timeout 5 scan on >/dev/null 2>&1 &
+ SCAN_PID=$!
+ sleep 4
+ kill "$SCAN_PID" 2>/dev/null || true
+ wait "$SCAN_PID" 2>/dev/null || true
+ sleep 1
+
+ notify-send "BT Recovery" "Put device in pairing mode!"
+ bluetoothctl pair "$TARGET_MAC"
+ bluetoothctl trust "$TARGET_MAC"
+
+ if bluetoothctl connect "$TARGET_MAC"; then
+ notify-send "BT Switch" "$SELECTION repaired and connected!"
+ else
+ notify-send "BT ERROR" "Repair fallback routing failed."
+ fi
+else
+ notify-send "BT ERROR" "Failed to link with $SELECTION. Check pairing state or other devices."
+fi
diff --git a/bin/.bin/new-episode b/bin/.bin/new-episode
deleted file mode 100755
index c8a2305..0000000
--- a/bin/.bin/new-episode
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/usr/bin/env bash
-
-if [ -z "$1" ]; then
- echo "Usage: new-episode <number> <name>"
- exit 1
-fi
-
-EP_NUM=$(printf "%03d" "$1")
-
-# Capture the Name (Shift the first arg so we can join the rest).
-shift
-RAW_NAME="${*:-untitled}"
-
-# Create the Title (Capitalize first letter of every word).
-# Using a simple sed regex to capitalize words.
-EP_TITLE=$(echo "$RAW_NAME" | sed 's/\b./\U&/g')
-
-# Create the Filename Slug (Lower case and replace spaces with hyphens)
-# tr '[:upper:]' '[:lower:]' handles the casing
-# tr ' ' '-' handles the spaces
-SLUG=$(echo "$RAW_NAME" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
-FILENAME="episode-${EP_NUM}-${SLUG}.php"
-
-# Generate the file
-cat <<EOF > "$FILENAME"
-<?php
-
-declare(strict_types=1);
-
-/**
- * Episode ${EP_NUM}: ${EP_TITLE}
- * The Coding Brummie Fundamental PHP Series
- */
-
-EOF
diff --git a/bin/.bin/open-bookmark.sh b/bin/.bin/open-bookmark.sh
new file mode 100755
index 0000000..67e724b
--- /dev/null
+++ b/bin/.bin/open-bookmark.sh
@@ -0,0 +1,23 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+BOOKMARKS_FILE="$DOTFILES_REPO/bookmarks.txt"
+
+if [ ! -f "$BOOKMARKS_FILE" ] || [ ! -s "$BOOKMARKS_FILE" ]; then
+ notify-send "Bookmarks" "Your bookmarks file is empty or missing."
+ exit 1
+fi
+
+SELECTION=$(cut -d'|' -f1 "$BOOKMARKS_FILE" | rofi -dmenu -p "Go To:")
+
+if [ -z "$SELECTION" ]; then
+ exit 0
+fi
+
+URL=$(grep "^$SELECTION|" "$BOOKMARKS_FILE" | head -n 1 | cut -d'|' -f2)
+
+if [ -n "$URL" ]; then
+ firefox "$URL" &
+else
+ notify-send "Error" "Could not resolve the URL for: $SELECTION"
+fi
diff --git a/bin/.bin/power.sh b/bin/.bin/power.sh
new file mode 100755
index 0000000..e17bae3
--- /dev/null
+++ b/bin/.bin/power.sh
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+declare -A actions
+actions[Reboot]="systemctl reboot"
+actions[Shutdown]="systemctl poweroff"
+
+SELECTION=$(printf "Reboot\nShutdown" | rofi -dmenu -p "")
+
+if [ -z "$SELECTION" ]; then
+ exit 0
+fi
+
+if [ -z "${actions[$SELECTION]:-}" ]; then
+ notify-send "ERROR" "Invalid choice: $SELECTION"
+ exit 1
+fi
+
+notify-send "System" "Initiating $SELECTION..."
+sleep 0.5
+
+${actions[$SELECTION]}