diff options
author | NeodarZ <neodarz@neodarz.ovh> | 2016-09-21 20:06:02 +0200 |
---|---|---|
committer | NeodarZ <neodarz@neodarz.ovh> | 2016-09-21 20:06:02 +0200 |
commit | f0b7ce9877b22014022ff1a3035a2f3be262b337 (patch) | |
tree | a37046f05a746886bb336ec42e8997632cd0aaf9 /i3/blocks/memory | |
parent | afb981f0fe8fa0de77f7451d6907f5094c38f1b5 (diff) | |
parent | 78db7d43845d3ea276b8028bec6d67b5a5641a1b (diff) | |
download | dotfiles-f0b7ce9877b22014022ff1a3035a2f3be262b337.tar.xz dotfiles-f0b7ce9877b22014022ff1a3035a2f3be262b337.zip |
Ajout de la police awesome
Diffstat (limited to 'i3/blocks/memory')
-rwxr-xr-x | i3/blocks/memory | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/i3/blocks/memory b/i3/blocks/memory new file mode 100755 index 0000000..866e7c3 --- /dev/null +++ b/i3/blocks/memory @@ -0,0 +1,69 @@ +#!/bin/bash + +# First argument is source (mem/swap), second is output value +# Check /proc/meminfo for possible instances +INSTANCE="${BLOCK_INSTANCE:-mem;free}" + +SOURCE=$(echo "${INSTANCE}" | awk -F ';' '{print $1}') +DISPLAY=$(echo "${INSTANCE}" | awk -F ';' '{print $2}') + +if [[ "${SOURCE}" = "mem" ]]; then + URGENT_VALUE=90 +elif [[ "${SOURCE}" = "swap" ]]; then + URGENT_VALUE=50 +fi + +if [[ "${DISPLAY}" = "" ]]; then + DISPLAY="free" +fi + +ONE_KB=1024 +ONE_MB=$(echo "${ONE_KB}*1024" | bc -l) +ONE_GB=$(echo "${ONE_MB}*1024" | bc -l) +ONE_TB=$(echo "${ONE_GB}*1024" | bc -l) + +# Grep the value and remove KB so we can calculate with it later +#MEMINFO=$(cat /proc/meminfo | grep "${INSTANCE}" | awk -F ':' '{print $2}' | tr -d ' kB') +MEMORY_INFOS=$(cat /proc/meminfo) +SOURCE_TOTAL=$(echo "${MEMORY_INFOS}" | grep -i "${SOURCE}total" | awk -F ':' '{print $2}' | tr -d ' kB') + +if [[ "${SOURCE_TOTAL}" -le 0 ]]; then + exit +fi + +SOURCE_FREE=$(echo "${MEMORY_INFOS}" | grep -i "${SOURCE}available" | awk -F ':' '{print $2}' | tr -d ' kB') +SOURCE_USED=$(echo "scale=0; ${SOURCE_TOTAL}-${SOURCE_FREE}" | bc -l) +SOURCE_PERC=$(echo "scale=0; (${SOURCE_USED}*100)/${SOURCE_TOTAL}" | bc -l) + +if [[ "${DISPLAY}" = "free" ]]; then + MEMINFO="${SOURCE_FREE}" +elif [[ "${DISPLAY}" = "used" ]]; then + MEMINFO="${SOURCE_USED}" +elif [[ "${DISPLAY}" = "total" ]]; then + MEMINFO="${SOURCE_TOTAL}" +elif [[ "${DISPLAY}" = "perc" ]]; then + MEMINFO="${SOURCE_PERC}%" +fi + +if [[ "${DISPLAY}" != "perc" ]]; then + # Convert KB meminfo to bytes + MEMINFO=$(echo "${MEMINFO}*${ONE_KB}" | bc -l) + + if [[ "${MEMINFO}" -ge "${ONE_TB}" ]]; then + MEMINFO=$(echo "scale=3;${MEMINFO}/${ONE_TB}" | bc -l)"tb" + elif [[ "${MEMINFO}" -ge "${ONE_GB}" ]]; then + MEMINFO=$(echo "scale=2;${MEMINFO}/${ONE_GB}" | bc -l)"gb" + elif [[ "${MEMINFO}" -ge "${ONE_MB}" ]]; then + MEMINFO=$(echo "scale=1;${MEMINFO}/${ONE_MB}" | bc -l)"mb" + else + MEMINFO=$(echo "scale=0;${MEMINFO}/${ONE_KB}" | bc -l)"kb" + fi +fi + +echo "${MEMINFO}" +echo "${MEMINFO}" +echo "" + +if [[ "${SOURCE_PERC}" -gt "${URGENT_VALUE}" ]]; then + exit 33 +fi
\ No newline at end of file |