From 161b7c1354f67c3234e0ad15699509c263916772 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 14 Nov 2022 21:23:52 -0500 Subject: [PATCH] Add sound to waybar on linux. --- .../roles/sway/files/waybar_sound_linux.bash | 37 +++++++++++++++++++ ansible/roles/sway/tasks/linux.yaml | 8 ++++ 2 files changed, 45 insertions(+) create mode 100644 ansible/roles/sway/files/waybar_sound_linux.bash diff --git a/ansible/roles/sway/files/waybar_sound_linux.bash b/ansible/roles/sway/files/waybar_sound_linux.bash new file mode 100644 index 0000000..08f3101 --- /dev/null +++ b/ansible/roles/sway/files/waybar_sound_linux.bash @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# +# Read volume status in FreeBSD +set -euo pipefail +IFS=$'\n\t' +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +SLEEP_INTERVAL=${SLEEP_INTERVAL:-30} + +while true; do + current_vol_decimal=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | sed 's/Volume: //g') + current_vol_percent=$(bc -s <<<"$current_vol_decimal * 100") + current_vol_percent=${current_vol_percent%.*} # Remove decimal + tooltip="$(wpctl status)" + tooltip=${tooltip//$'\n'/\\n} + tooltip=${tooltip//$'\t'/\\t} + class="" + icon="" + + if [ $current_vol_percent -eq 0 ]; then + icon="🔇" + elif [ $current_vol_percent -le 50 ]; then + icon="🔉" + else + icon="🔊" + fi + + jq --unbuffered --compact-output <