This repository has been archived on 2019-02-28. You can view files and clone it, but cannot push or open issues or pull requests.
2018-08-13 12:24:39 +02:00

42 lines
1.4 KiB
Bash

[[ "$BLOCK_BUTTON" == 2 ]] && i3-sensible-terminal -e htop
[[ $BLOCK_INSTANCE =~ (phys|swap) ]] && TYPE=${BASH_REMATCH[1]}
MEMINFO=$(cat /proc/meminfo)
if [[ $MEMINFO =~ MemTotal:[[:space:]]+([0-9]+) ]]; then
PHYS_TOTAL=${BASH_REMATCH[1]}
PHYS_TOTAL=$((${PHYS_TOTAL} / 1024**2))
fi
if [[ $MEMINFO =~ MemAvailable:[[:space:]]+([0-9]+) ]]; then
PHYS_AVAILABLE=${BASH_REMATCH[1]}
PHYS_AVAILABLE=$((${PHYS_AVAILABLE} / 1024**2))
PHYS_AVAILABLE_M=$((${PHYS_AVAILABLE} / 1024))
fi
if [[ $MEMINFO =~ SwapTotal:[[:space:]]+([0-9]+) ]]; then
SWAP_TOTAL=${BASH_REMATCH[1]}
SWAP_TOTAL=$((${SWAP_TOTAL} / 1024**2))
fi
if [[ $MEMINFO =~ SwapFree:[[:space:]]+([0-9]+) ]]; then
SWAP_AVAILABLE=${BASH_REMATCH[1]}
SWAP_AVAILABLE=$((${SWAP_AVAILABLE} / 1024**2))
SWAP_AVAILABLE_M=$((${SWAP_AVAILABLE} / 1024))
fi
if [[ "$TYPE" == "" ]]; then
MEM_FREE=$((${PHYS_AVAILABLE} + ${SWAP_AVAILABLE}))
MEM_TOTAL=$((${PHYS_TOTAL} + ${SWAP_TOTAL}))
if [[ "$MEM_FREE" -gt 2 ]]; then
LONG_TEXT="${PHYS_AVAILABLE}+${SWAP_AVAILABLE}G"
SHORT_TEXT="${PHYS_AVAILABLE}+${SWAP_AVAILABLE}G"
else
LONG_TEXT="${PHYS_AVAILABLE_M}+${SWAP_AVAILABLE}M"
SHORT_TEXT="${PHYS_AVAILABLE_M}+${SWAP_AVAILABLE}M"
fi
elif [[ "$TYPE" == "ram" ]]; then
MEM_FREE=${PHYS_AVAILABLE}
MEM_TOTAL=${PHYS_TOTAL}
elif [[ "$TYPE" == "swap" ]]; then
MEM_FREE=${SWAP_AVAILABLE}
MEM_TOTAL=${SWAP_TOTAL}
fi