init
This commit is contained in:
73
waybar/scripts/anc_control.sh
Executable file
73
waybar/scripts/anc_control.sh
Executable file
@@ -0,0 +1,73 @@
|
||||
#!/bin/bash
|
||||
|
||||
# --- CONFIGURATION ---
|
||||
# Your Pixel Buds Pro's MAC Address
|
||||
MAC_ADDRESS="B4:23:A2:09:D3:53"
|
||||
# --- END CONFIGURATION ---
|
||||
|
||||
# First, check if the device is connected using bluetoothctl.
|
||||
if bluetoothctl info "$MAC_ADDRESS" | grep -q "Connected: yes"; then
|
||||
# --- DEVICE IS CONNECTED ---
|
||||
|
||||
# This function gets the current ANC status and formats it for Waybar.
|
||||
get_status() {
|
||||
# Get the mode from pbpctrl. Redirect errors to null in case of a temporary glitch.
|
||||
current_mode=$(pbpctrl get anc 2>/dev/null)
|
||||
|
||||
# Fallback: If pbpctrl fails or returns 'unknown', hide the module.
|
||||
# This handles cases where buds are connected but not fully ready.
|
||||
if [[ $? -ne 0 || "$current_mode" == "unknown (0)"* || -z "$current_mode" ]]; then
|
||||
echo "{}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Set icon and tooltip based on the current mode.
|
||||
case "$current_mode" in
|
||||
"active")
|
||||
icon="ANC: Active"
|
||||
class="anc-active"
|
||||
;;
|
||||
"aware")
|
||||
icon="ANC: Aware"
|
||||
class="anc-aware"
|
||||
;;
|
||||
"off")
|
||||
icon="ANC: Off"
|
||||
class="anc-off"
|
||||
;;
|
||||
*)
|
||||
# Failsafe to hide the module if the mode is unrecognized.
|
||||
echo "{}"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
echo "{\"text\":\"$icon\", \"class\":\"$class\"}"
|
||||
}
|
||||
|
||||
# Handle click actions passed from Waybar.
|
||||
case "$1" in
|
||||
# Right-click: Cycle between active and aware modes.
|
||||
cycle)
|
||||
current_mode=$(pbpctrl get anc 2>/dev/null)
|
||||
if [[ "$current_mode" == "active" ]]; then
|
||||
pbpctrl set anc aware
|
||||
else
|
||||
pbpctrl set anc active
|
||||
fi
|
||||
sleep 0.1 # Brief pause for the state to update.
|
||||
;;
|
||||
# Left-click: Turn ANC off.
|
||||
off)
|
||||
pbpctrl set anc off
|
||||
sleep 0.1 # Brief pause for the state to update.
|
||||
;;
|
||||
esac
|
||||
|
||||
# Always display the current status after any action or on a scheduled interval.
|
||||
get_status
|
||||
|
||||
else
|
||||
# --- DEVICE IS NOT CONNECTED ---
|
||||
# Output an empty JSON object to completely hide the Waybar module.
|
||||
echo "{}"
|
||||
fi
|
12
waybar/scripts/cycle_audio_output.sh
Executable file
12
waybar/scripts/cycle_audio_output.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
SINKS=($(pactl list short sinks | awk '{print $2}'))
|
||||
CURRENT_SINK=$(pactl info | grep 'Default Sink' | cut -d ' ' -f3)
|
||||
NUM_SINKS=${#SINKS[@]}
|
||||
|
||||
for i in "${!SINKS[@]}"; do
|
||||
if [[ "${SINKS[$i]}" == "$CURRENT_SINK" ]]; then
|
||||
NEXT_INDEX=$(( (i + 1) % NUM_SINKS ))
|
||||
pactl set-default-sink "${SINKS[$NEXT_INDEX]}"
|
||||
break
|
||||
fi
|
||||
done
|
12
waybar/scripts/get_audio_output.sh
Executable file
12
waybar/scripts/get_audio_output.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
DEFAULT_SINK=$(pactl info | grep 'Default Sink' | cut -d ' ' -f3)
|
||||
DESCRIPTION=$(pactl list sinks | grep -A2 "Name: $DEFAULT_SINK" | grep "Description:" | cut -d ' ' -f2-)
|
||||
|
||||
if [ -z "$DESCRIPTION" ]; then
|
||||
DESCRIPTION=$DEFAULT_SINK
|
||||
fi
|
||||
|
||||
TEXT=$(echo "$DESCRIPTION" | cut -c -20)
|
||||
|
||||
printf '{"text": "%s", "tooltip": "%s"}
|
||||
' "$TEXT" "$DESCRIPTION"
|
49
waybar/scripts/pixelbuds.sh
Executable file
49
waybar/scripts/pixelbuds.sh
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/bin/bash
|
||||
|
||||
# --- CONFIGURATION ---
|
||||
# Your Pixel Buds Pro's MAC Address
|
||||
MAC_ADDRESS="B4:23:A2:09:D3:53"
|
||||
# --- END CONFIGURATION ---
|
||||
|
||||
# Check if the device is connected using bluetoothctl.
|
||||
if bluetoothctl info "$MAC_ADDRESS" | grep -q "Connected: yes"; then
|
||||
|
||||
# If connected, get battery info from pbpctrl.
|
||||
if battery_output=$(pbpctrl show battery); then
|
||||
# Use awk to grab the third field, which is the percentage or "unknown".
|
||||
left_bud=$(echo "$battery_output" | grep "left bud:" | awk '{print $3}')
|
||||
right_bud=$(echo "$battery_output" | grep "right bud:" | awk '{print $3}')
|
||||
|
||||
# If both buds are unknown (e.g., case is closed and buds are out of range),
|
||||
# or if the command output is empty, hide the module.
|
||||
if ([[ "$left_bud" == "unknown" ]] && [[ "$right_bud" == "unknown" ]]) || \
|
||||
[[ -z "$left_bud" && -z "$right_bud" ]]; then
|
||||
echo "{}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Prepare the display string for the left bud.
|
||||
if [[ "$left_bud" == "unknown" ]]; then
|
||||
left_display="L: ---"
|
||||
else
|
||||
left_display="L: $left_bud"
|
||||
fi
|
||||
|
||||
# Prepare the display string for the right bud.
|
||||
if [[ "$right_bud" == "unknown" ]]; then
|
||||
right_display="R: ---"
|
||||
else
|
||||
right_display="R: $right_bud"
|
||||
fi
|
||||
|
||||
# Format the final output for Waybar as JSON.
|
||||
printf '{"text": "%s | %s", "tooltip": "Pixel Buds Pro 2", "class": "connected"}\n' "$left_display" "$right_display"
|
||||
|
||||
else
|
||||
# pbpctrl failed to run, so hide the module.
|
||||
echo "{}"
|
||||
fi
|
||||
else
|
||||
# Not connected, output an empty JSON object to hide the module.
|
||||
echo "{}"
|
||||
fi
|
54
waybar/scripts/power-profile.sh
Executable file
54
waybar/scripts/power-profile.sh
Executable file
@@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to manage and display system76-power profiles for Waybar
|
||||
|
||||
# Define the available power profiles
|
||||
PROFILES=("Performance" "Balanced" "Battery")
|
||||
|
||||
# Get the current power profile
|
||||
CURRENT_PROFILE=$(system76-power profile | awk '/Power Profile/ {print $3}')
|
||||
|
||||
# Function to switch to the next profile
|
||||
switch_next_profile() {
|
||||
# Find the index of the current profile
|
||||
for i in "${!PROFILES[@]}"; do
|
||||
if [[ "${PROFILES[$i]}" == "$CURRENT_PROFILE" ]]; then
|
||||
current_index=$i
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Calculate the index of the next profile
|
||||
next_index=$(((current_index + 1) % ${#PROFILES[@]}))
|
||||
NEXT_PROFILE=${PROFILES[$next_index]}
|
||||
|
||||
# Switch to the next profile
|
||||
system76-power profile "$NEXT_PROFILE"
|
||||
}
|
||||
|
||||
# If the script is called with "next", switch the profile
|
||||
if [[ "$1" == "next" ]]; then
|
||||
switch_next_profile
|
||||
# After switching, get the new current profile
|
||||
CURRENT_PROFILE=$(system76-power profile | awk '/Power Profile/ {print $3}')
|
||||
fi
|
||||
|
||||
# Set an icon based on the current profile
|
||||
case $CURRENT_PROFILE in
|
||||
"Performance")
|
||||
ICON="🚀"
|
||||
;;
|
||||
"Balanced")
|
||||
ICON="⚖️"
|
||||
;;
|
||||
"Battery")
|
||||
ICON="🔋"
|
||||
;;
|
||||
*)
|
||||
ICON="❓"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Output in JSON format for Waybar
|
||||
printf '{"text": "%s", "tooltip": "Power Profile: %s", "class": "%s"}\n' "$ICON" "$CURRENT_PROFILE" "$(echo $CURRENT_PROFILE | tr '[:upper:]' '[:lower:]')"
|
||||
|
2
waybar/scripts/power.sh
Executable file
2
waybar/scripts/power.sh
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
wlogout -p layer-shell
|
54
waybar/scripts/tlp-profile.sh
Executable file
54
waybar/scripts/tlp-profile.sh
Executable file
@@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
|
||||
# --- Configuration ---
|
||||
CRITICAL_THRESHOLD=15
|
||||
WARNING_THRESHOLD=50
|
||||
# ---------------------
|
||||
|
||||
# Get the battery path from upower
|
||||
battery_path=$(upower -e | grep 'BAT')
|
||||
|
||||
# Handle case where no battery is found
|
||||
if [ -z "$battery_path" ]; then
|
||||
# Check if we are on AC power anyway
|
||||
if [[ $(tlp-stat -s | grep "Power source" | awk '{print $4}') == "AC" ]]; then
|
||||
printf '{"text": "", "tooltip": "AC Power (No Battery)", "class": "ac"}\n'
|
||||
else
|
||||
printf '{"text": "", "tooltip": "Error: Battery not found", "class": "unknown"}\n'
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Get battery percentage and state
|
||||
percentage=$(upower -i "$battery_path" | grep "percentage" | awk '{print $2}' | tr -d '%')
|
||||
state=$(upower -i "$battery_path" | grep "state" | awk '{print $2}')
|
||||
tlp_profile=$(tlp-stat -s | grep "Power source" | awk '{print $4}')
|
||||
|
||||
# Set icon, class, and tooltip based on state and percentage
|
||||
if [ "$state" == "charging" ] || [ "$tlp_profile" == "AC" ]; then
|
||||
icon=""
|
||||
class="charging"
|
||||
tooltip="TLP: AC | Charging at ${percentage}%"
|
||||
elif [ "$state" == "discharging" ]; then
|
||||
tooltip="TLP: Battery | Discharging at ${percentage}%"
|
||||
if [ "$percentage" -le "$CRITICAL_THRESHOLD" ]; then
|
||||
icon="" # Very low
|
||||
class="critical"
|
||||
elif [ "$percentage" -le "$WARNING_THRESHOLD" ]; then
|
||||
icon="" # Low
|
||||
class="warning"
|
||||
elif [ "$percentage" -le 85 ]; then
|
||||
icon="" # Healthy
|
||||
class="bat"
|
||||
else
|
||||
icon="" # Full
|
||||
class="bat"
|
||||
fi
|
||||
else # Fallback for "fully-charged", "pending-charge", etc.
|
||||
icon=""
|
||||
class="charging"
|
||||
tooltip="TLP: AC | Fully Charged at ${percentage}%"
|
||||
fi
|
||||
|
||||
# Output JSON for Waybar
|
||||
printf '{"text": "%s %s%%", "tooltip": "%s", "class": "%s"}\n' "$icon" "$percentage" "$tooltip" "$class"
|
Reference in New Issue
Block a user