Created
February 13, 2018 10:21
-
-
Save ivanbogomoloff/fae33ad35bde0c100cde3731e32a8156 to your computer and use it in GitHub Desktop.
i3wm free memory and status modify script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###File name is free_m | |
mem_free() | |
{ | |
TYPE=free | |
awk -v type=$TYPE ' | |
/^MemTotal:/ { | |
mem_total=$2 | |
} | |
/^MemFree:/ { | |
mem_free=$2 | |
} | |
/^Buffers:/ { | |
mem_free+=$2 | |
} | |
/^Cached:/ { | |
mem_free+=$2 | |
} | |
/^SwapTotal:/ { | |
swap_total=$2 | |
} | |
/^SwapFree:/ { | |
swap_free=$2 | |
} | |
END { | |
if (type == "swap") { | |
free=swap_free/1024/1024 | |
used=(swap_total-swap_free)/1024/1024 | |
total=swap_total/1024/1024 | |
} else { | |
free=mem_free/1024/1024 | |
used=(mem_total-mem_free)/1024/1024 | |
total=mem_total/1024/1024 | |
} | |
pct=used/total*100 | |
# full text | |
printf("%.1fG/%.1fG (%.f%%)\n", used, total, pct) | |
# short text | |
#printf("%.f%%\n", pct) | |
# color | |
if (pct > 90) { | |
print("#FF0000\n") | |
} else if (pct > 80) { | |
print("#FFAE00\n") | |
} else if (pct > 70) { | |
print("#FFF600\n") | |
} | |
} | |
' /proc/meminfo | |
} | |
##### IN i3status_custom.sh | |
#!/bin/bash | |
i3status | while : | |
#do | |
# read line | |
# echo "mystuff | $line" || exit 1 | |
#done | |
source ~/.i3/free_m | |
FREE_MEM=$(mem_free) | |
do | |
read line | |
LGCODE=$(xset -q | grep "LED mask:" | awk '{ print $10 }') | |
if [ $LGCODE == 00000000 ] || [ $LGCODE == 00000002 ] | |
then | |
echo "en | $FREE_MEM | $line" || exit 1 | |
fi | |
if [ $LGCODE == 00001004 ] | |
then | |
echo "ru | $FREE_MEM | $line" || exit 1 | |
fi | |
#echo "$dat | $line" || exit 1 | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment