dotfiles/common/.config/sketchybar/plugins/mem.sh.org
2024-10-01 17:42:59 -05:00

16 lines
774 B
Org Mode
Executable file

#+title: SketchyBar Memory Plugin
Get the memory in use and return that as a percent.
#+begin_src sh :tangle ~/.config/sketchybar/plugins/mem.sh :mkdirp yes :tangle-mode o755
#!/bin/sh
hw_pagesize="$(sysctl -n hw.pagesize)"
mem_total="$(($(sysctl -n hw.memsize) / 1024))"
pages_app="$(($(sysctl -n vm.page_pageable_internal_count) - $(sysctl -n vm.page_purgeable_count)))"
pages_wired="$(vm_stat | awk '/ wired/ { print $4 }')"
pages_compressed="$(vm_stat | awk '/ occupied/ { printf $5 }')"
pages_compressed="${pages_compressed:-0}"
mem_used="$(((pages_app + ${pages_wired//.} + ${pages_compressed//.}) * hw_pagesize / 1024))"
mem_percent=$((mem_perc=$mem_used * 100 / $mem_total))
sketchybar --set "$NAME" icon="󰆼" label="$mem_percent%"
#+end_src