speedwm-personal/modules/module_ram

77 lines
1.7 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# ram module for status/stellar
# load config
2022-10-27 17:51:19 +02:00
. $HOME/.config/speedwm/statusrc
2022-10-25 19:23:36 +02:00
BINDIR="$(dirname $(command -v speedwm_status))/"
ARG1="$1"
CLICK() {
# values
RAM_USED="$(echo "$(free -h --giga | awk '/^Mem/ {print $3}')B")"
RAM_TOTAL="$(echo "$(free -h --giga | awk '/^Mem/ {print $2}')B")"
RAM_LEFT="$(echo "$(free -h --giga | awk '/^Mem/ {print $7}')B")"
ICON="$ITEM1_ICON"
BUTTON="$(cat /tmp/speedwm-button)"
case "$TERMINAL" in
"") TERMINAL=st
esac
case "$BUTTON" in
2022-11-12 12:59:04 +01:00
"2") command -v notify-send > /dev/null && notify-send "$(ps axch -o cmd:12,%mem --sort=%mem | tail -n 10)" ; exit ;;
"3") $TERMINAL -e htop ;;
esac
# no spacing if there's no icon
if [ "$ICON" != "" ]; then
ICONSPACING=" " # one character spacing
fi
# send the notification
SEND_NOTIF() {
FULL_RAM="$(printf "${ICON}${ICONSPACING}Used: $RAM_USED\nFree: $RAM_LEFT\nTotal: $RAM_TOTAL\n")"
notify-send "$FULL_RAM"
echo "Notification sent successfully!"
echo "INFO: $FULL_RAM"
exit 0
}
command -v notify-send > /dev/null && SEND_NOTIF
echo "FATAL: libnotify not installed, can't send notification."
exit 1
}
# information itself
PRINT() {
if [ "$ENABLE_ITEM1" = "true" ]; then
# Used RAM
if [ -e "${BINDIR}free" ]; then
USEDRAM="$(echo "$(free -h --giga | awk '/^Mem/ {print $3}')B")"
fi
# Total RAM
if [ -e "${BINDIR}free" ]; then
TOTALRAM="$(echo "$(free -h --giga | awk '/^Mem/ {print $2}')B")"
fi
if [ -e "${BINDIR}free" ]; then
echo "$ITEM1_SEPARATOR $ITEM1_ICON $ITEM1_FORMAT" | sed "s|@u|$USEDRAM|; s|@t|$TOTALRAM|"
fi
echo "$ITEM1_APPEND"
fi
}
# argument 1
case "$ARG1" in
"") CLICK ;;
"--print") PRINT > /tmp/module_ram ;;
"--click") CLICK ;;
esac