2022-10-08 02:31:35 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# ram module for status/stellar
|
|
|
|
|
2022-10-21 13:35:02 +02:00
|
|
|
# load config
|
2022-11-27 01:12:14 +01:00
|
|
|
module_config
|
|
|
|
[ -e "$HOME/.config/speedwm/statusrc" ] && . $HOME/.config/speedwm/statusrc
|
|
|
|
[ "$ENABLE_ITEM1" = "true" ] || exit
|
2022-12-22 23:11:38 +01:00
|
|
|
[ -e "/tmp/module_ram_hidden" ] && exit
|
2022-11-27 01:12:14 +01:00
|
|
|
command -v free > /dev/null || exit
|
2022-10-08 12:47:57 +02:00
|
|
|
|
2022-11-27 01:12:14 +01:00
|
|
|
# get status
|
|
|
|
GETSTAT() {
|
|
|
|
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")"
|
|
|
|
}
|
|
|
|
|
|
|
|
GETSTAT
|
2022-10-08 12:47:57 +02:00
|
|
|
|
2022-10-21 13:35:02 +02:00
|
|
|
CLICK() {
|
2022-11-27 01:12:14 +01:00
|
|
|
# values
|
|
|
|
ICON="$ITEM1_ICON"
|
|
|
|
[ -e "/tmp/speedwm-button" ] && BUTTON="$(cat /tmp/speedwm-button)"
|
|
|
|
[ -z "$TERMINAL" ] && TERMINAL=st
|
2022-12-16 17:35:03 +01:00
|
|
|
[ -n "$ICON" ] && ICONSPACING=" " # one character spacing
|
2022-12-22 23:11:38 +01:00
|
|
|
|
2022-11-27 01:12:14 +01:00
|
|
|
# check value of button
|
|
|
|
case "$BUTTON" in
|
|
|
|
"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 ; exit ;;
|
|
|
|
esac
|
2022-12-22 23:11:38 +01:00
|
|
|
|
2022-11-27 01:12:14 +01:00
|
|
|
# send the notification
|
|
|
|
SEND_NOTIF() {
|
|
|
|
FULL_RAM="$(printf "${ICON}${ICONSPACING}Used: $RAM_USED\nFree: $RAM_LEFT\nTotal: $RAM_TOTAL\n")"
|
|
|
|
notify-send "$FULL_RAM"
|
2022-12-22 23:11:38 +01:00
|
|
|
|
2022-11-27 01:12:14 +01:00
|
|
|
# some information
|
|
|
|
echo "Notification sent successfully!"
|
|
|
|
echo "INFO: $FULL_RAM"
|
2022-12-22 23:11:38 +01:00
|
|
|
|
2022-11-27 01:12:14 +01:00
|
|
|
return
|
|
|
|
}
|
2022-12-22 23:11:38 +01:00
|
|
|
|
2022-11-27 01:12:14 +01:00
|
|
|
command -v notify-send > /dev/null && SEND_NOTIF || echo "FATAL: libnotify not installed, can't send notification."
|
2022-12-22 23:11:38 +01:00
|
|
|
|
2022-11-27 01:12:14 +01:00
|
|
|
return
|
2022-10-21 13:35:02 +02:00
|
|
|
}
|
2022-10-08 02:31:35 +02:00
|
|
|
|
2022-10-21 13:35:02 +02:00
|
|
|
# information itself
|
|
|
|
PRINT() {
|
2022-11-27 01:12:14 +01:00
|
|
|
echo "$ITEM1_SEPARATOR $ITEM1_ICON $ITEM1_FORMAT" | sed "s|@u|$RAM_USED|; s|@t|$RAM_TOTAL|; s|@l|$RAM_LEFT|"
|
2022-10-08 02:31:35 +02:00
|
|
|
}
|
|
|
|
|
2022-10-21 13:35:02 +02:00
|
|
|
# argument 1
|
2022-11-27 01:12:14 +01:00
|
|
|
case "$1" in
|
2022-10-21 13:35:02 +02:00
|
|
|
"") CLICK ;;
|
2022-11-26 19:16:22 +01:00
|
|
|
"--print-file") PRINT > /tmp/module_ram ;;
|
|
|
|
"--print") PRINT ;;
|
2022-10-21 13:35:02 +02:00
|
|
|
"--click") CLICK ;;
|
|
|
|
esac
|