From 4ec4ca0e6385e9e68c76025c545176a05c635c1a Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 28 Oct 2022 20:45:19 -0400 Subject: [PATCH] Add free memory to FreeBSD's waybar. --- .../roles/base/files/cleanup_temporary_files | 2 +- ansible/roles/sway/files/style.css | 1 + .../files/waybar_available_memory_freebsd | 32 +++++++++++++++++++ ansible/roles/sway/files/waybar_config.json | 8 ++++- ansible/roles/sway/tasks/freebsd.yaml | 2 ++ 5 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 ansible/roles/sway/files/waybar_available_memory_freebsd diff --git a/ansible/roles/base/files/cleanup_temporary_files b/ansible/roles/base/files/cleanup_temporary_files index dd30936..71827a4 100644 --- a/ansible/roles/base/files/cleanup_temporary_files +++ b/ansible/roles/base/files/cleanup_temporary_files @@ -1,4 +1,4 @@ #!/usr/bin/env bash # # Delete temporary files on entire disk -find / -type f -name '*.orig' -delete -or -name '*~' -delete +find / -type f -name '*.orig' -delete -or -name '*~' -delete -print diff --git a/ansible/roles/sway/files/style.css b/ansible/roles/sway/files/style.css index 08510bf..1da6e35 100644 --- a/ansible/roles/sway/files/style.css +++ b/ansible/roles/sway/files/style.css @@ -50,6 +50,7 @@ #battery, #clock, #cpu, +#custom-available_memory, #custom-battery, #custom-clock, #idle_inhibitor, diff --git a/ansible/roles/sway/files/waybar_available_memory_freebsd b/ansible/roles/sway/files/waybar_available_memory_freebsd new file mode 100644 index 0000000..482ac06 --- /dev/null +++ b/ansible/roles/sway/files/waybar_available_memory_freebsd @@ -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 + page_size=$(sysctl -n hw.pagesize) + free_pages=$(sysctl -n vm.stats.vm.v_free_count) + free_bytes=$((page_size * free_pages)) + total_pages=$(sysctl -n vm.stats.vm.v_page_count) + free_percent=$((100 * free_pages / total_pages)) + text="" + + if [ $free_bytes > $((1024 * 1024 * 1024)) ]; then + text="$((free_bytes / 1024 / 1024 / 1024)) GiB" + fi + + tooltip="${free_percent}%" + + jq --unbuffered --compact-output <