improve
This commit is contained in:
62
bluetooth-sway.sh
Executable file
62
bluetooth-sway.sh
Executable file
@@ -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
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user