#!/usr/bin/bash set -euo pipefail mode="${1:-status}" read -r mem_total mem_used swap_total swap_used < 0) printf "%.1f", (used/total)*100; else print "0.0" }')" if [[ "$swap_total" -gt 0 ]]; then swap_used_h="$(format_bytes "$swap_used")" swap_total_h="$(format_bytes "$swap_total")" swap_pct="$(awk -v used="$swap_used" -v total="$swap_total" 'BEGIN { if (total > 0) printf "%.1f", (used/total)*100; else print "0.0" }')" else swap_used_h="0.0B" swap_total_h="0.0B" swap_pct="0.0" fi case "$mode" in ram) notify-send "RAM usage" "${mem_used_h} / ${mem_total_h} (${mem_pct}%)" ;; swap) if [[ "$swap_total" -gt 0 ]]; then notify-send "Swap usage" "${swap_used_h} / ${swap_total_h} (${swap_pct}%)" else notify-send "Swap usage" "Swap is disabled" fi ;; status) if [[ "$swap_total" -gt 0 ]]; then tooltip="Left click: RAM (${mem_used_h}/${mem_total_h}, ${mem_pct}%)\nRight click: Swap (${swap_used_h}/${swap_total_h}, ${swap_pct}%)" else tooltip="Left click: RAM (${mem_used_h}/${mem_total_h}, ${mem_pct}%)\nRight click: Swap (disabled)" fi printf '{"text":"","tooltip":"%s"}\n' "$tooltip" ;; esac