From 8e0c4f9a70453dc4eb31c159044fcb8f2f5f754f Mon Sep 17 00:00:00 2001 From: k4rli Date: Wed, 9 Jul 2025 07:17:30 +0300 Subject: [PATCH] improve --- bluetooth-sway.sh | 62 ++++++++++++++++++++++++++++++++++++++++++++ i3status-rust.toml | 13 +++++++++- install-arch-sway.sh | 7 +++++ weather-sway.sh | 2 +- 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100755 bluetooth-sway.sh diff --git a/bluetooth-sway.sh b/bluetooth-sway.sh new file mode 100755 index 0000000..b2faddb --- /dev/null +++ b/bluetooth-sway.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +set -Eeu -o pipefail + +# Bluetooth script for i3status-rust +# Shows connected Bluetooth devices + +BT_ICON="" + +# Check if bluetoothctl is available +if ! command -v bluetoothctl >/dev/null 2>&1; then + echo "$BT_ICON Not available" + exit 0 +fi + +# Check if Bluetooth is powered on +BLUETOOTH_POWERED=$(bluetoothctl show | grep "Powered:" | awk '{print $2}') +if [ "$BLUETOOTH_POWERED" != "yes" ]; then + echo "$BT_ICON Off" + exit 0 +fi + +# Get connected devices +CONNECTED_DEVICES=$(bluetoothctl devices Connected | grep "^Device" | awk '{for(i=3;i<=NF;i++) printf "%s ", $i; print ""}' | sed 's/ $//') + +if [ -z "$CONNECTED_DEVICES" ]; then + echo "$BT_ICON No devices" +else + # Limit the display to first 2 devices to avoid cluttering the bar + DEVICE_COUNT=$(echo "$CONNECTED_DEVICES" | wc -w) + if [ "$DEVICE_COUNT" -le 2 ]; then + echo "$BT_ICON $CONNECTED_DEVICES" + else + FIRST_TWO=$(echo "$CONNECTED_DEVICES" | cut -d' ' -f1-2) + echo "$BT_ICON $FIRST_TWO (+$((DEVICE_COUNT - 2)))" + fi +fi + +# Handle click events (for i3status-rust custom block) +if [ "${BLOCK_BUTTON:-}" = "1" ]; then + # Left click - show all connected devices with details + DETAILED_DEVICES=$(bluetoothctl devices Connected | while read -r line; do + MAC=$(echo "$line" | awk '{print $2}') + NAME=$(echo "$line" | awk '{for(i=3;i<=NF;i++) printf "%s ", $i; print ""}' | sed 's/ $//') + echo "• $NAME ($MAC)" + done) + + if [ -n "$DETAILED_DEVICES" ]; then + notify-send "Bluetooth Devices" "$DETAILED_DEVICES" -t 5000 + else + notify-send "Bluetooth" "No devices connected" -t 3000 + fi +elif [ "${BLOCK_BUTTON:-}" = "3" ]; then + # Right click - open bluetooth manager + if command -v blueman-manager >/dev/null 2>&1; then + blueman-manager >/dev/null 2>&1 & + elif command -v gnome-bluetooth-panel >/dev/null 2>&1; then + gnome-bluetooth-panel >/dev/null 2>&1 & + else + notify-send "Bluetooth" "No Bluetooth manager found" -t 3000 + fi +fi \ No newline at end of file diff --git a/i3status-rust.toml b/i3status-rust.toml index 8491db8..c6b836b 100644 --- a/i3status-rust.toml +++ b/i3status-rust.toml @@ -38,6 +38,17 @@ mac = "" format = " $icon $label " disconnected_format = "" +# Custom Bluetooth connected devices block +[[block]] +block = "custom" +command = "~/.config/sway/bluetooth-sway.sh" +format = " $text " +interval = 10 +click = [ + {button = "left", update = true}, + {button = "right", update = true}, +] + # Custom weather block using your wttr.in script # [[block]] # block = "custom" @@ -53,7 +64,7 @@ disconnected_format = "" # Uncomment and modify this block if you want weather for a different city [[block]] block = "custom" -command = "weather_location='Tallinn' ~/.config/sway/weather-sway.sh" +command = "~/.config/sway/weather-sway.sh" format = "$text" interval = 1800 diff --git a/install-arch-sway.sh b/install-arch-sway.sh index 08161e7..b2eda68 100755 --- a/install-arch-sway.sh +++ b/install-arch-sway.sh @@ -38,6 +38,13 @@ cp weather-sway.sh ~/.config/sway/weather-sway.sh chmod +x ~/.config/sway/weather-sway.sh echo "✓ Weather script installed to ~/.config/sway/weather-sway.sh" +# === BLUETOOTH SCRIPT === +echo "" +echo "Installing bluetooth script..." +cp bluetooth-sway.sh ~/.config/sway/bluetooth-sway.sh +chmod +x ~/.config/sway/bluetooth-sway.sh +echo "✓ Bluetooth script installed to ~/.config/sway/bluetooth-sway.sh" + # === VOLUME NOTIFY SCRIPT === # Comment out this section if you don't want volume notifications if [ -f volume-notify-sway.sh ]; then diff --git a/weather-sway.sh b/weather-sway.sh index 40a0ba9..bedbc99 100755 --- a/weather-sway.sh +++ b/weather-sway.sh @@ -6,7 +6,7 @@ set -Eeu -o pipefail # Based on the original weather script but adapted for Sway/i3status-rust # Information on the various formats: https://github.com/chubin/wttr.in -VALUE_WEATHER_FORMAT=${weather_format:-"1"} +VALUE_WEATHER_FORMAT=${weather_format:-"%c%f"} VALUE_WEATHER_FORMAT="?format=${VALUE_WEATHER_FORMAT}" # Determine units to use for temperature