Add waybar available memory script for Linux.

This commit is contained in:
Tom Alexander 2022-10-29 15:54:55 -04:00
parent f0162375d0
commit a9d1e9f86a
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
6 changed files with 37 additions and 3 deletions

View File

@ -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 <<EOF
{
"text":"${text}",
"tooltip":"${tooltip}",
"percentage":${free_percent}
}
EOF
sleep $SLEEP_INTERVAL
done

View File

@ -47,7 +47,7 @@
loop:
- src: launch_sway_freebsd.bash
dest: /usr/local/bin/launch_sway
- src: waybar_battery_freebsd
- src: waybar_battery_freebsd.bash
dest: /usr/local/bin/waybar_custom_battery
- src: waybar_available_memory_freebsd
- src: waybar_available_memory_freebsd.bash
dest: /usr/local/bin/waybar_custom_available_memory

View File

@ -8,5 +8,7 @@
loop:
- src: launch_sway_linux.bash
dest: /usr/local/bin/launch_sway
- src: waybar_battery_linux
- src: waybar_battery_linux.bash
dest: /usr/local/bin/waybar_custom_battery
- src: waybar_available_memory_linux.bash
dest: /usr/local/bin/waybar_custom_available_memory