diff --git a/ansible/roles/sway/files/waybar_available_memory_freebsd b/ansible/roles/sway/files/waybar_available_memory_freebsd.bash similarity index 100% rename from ansible/roles/sway/files/waybar_available_memory_freebsd rename to ansible/roles/sway/files/waybar_available_memory_freebsd.bash diff --git a/ansible/roles/sway/files/waybar_available_memory_linux.bash b/ansible/roles/sway/files/waybar_available_memory_linux.bash new file mode 100644 index 0000000..57f609b --- /dev/null +++ b/ansible/roles/sway/files/waybar_available_memory_linux.bash @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# +# Read memory usage in FreeBSD +set -euo pipefail +IFS=$'\n\t' +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +SLEEP_INTERVAL=${SLEEP_INTERVAL:-30} + +while true; do + memory_usage=$(free --bytes --wide) + total_bytes=$(grep 'Mem:' <<<"$memory_usage" | awk '{print $2}') + free_bytes=$(grep 'Mem:' <<<"$memory_usage" | awk '{print $4}') + + free_percent=$((100 * free_bytes / total_bytes)) + text="" + + if [ $free_bytes -ge $((1024 * 1024 * 1024)) ]; then + text="$((free_bytes / 1024 / 1024 / 1024)) GiB" + fi + + tooltip="${free_percent}%" + + jq --unbuffered --compact-output <