#!/bin/bash
#Script to display CPU and RAM usage, in tint2 toolbar (use as an "Executor" in tint2rc config file)
#Snore function- found somewhere in the Internet, thanks to the original creator!!!
snore()
{
    local IFS
    [[ -n "${_snore_fd:-}" ]] || { exec {_snore_fd}<> <(:); } 2>/dev/null ||
    {
        # workaround for MacOS and similar systems
        local fifo
        fifo=$(mktemp -u)
        mkfifo -m 700 "$fifo"
        exec {_snore_fd}<>"$fifo"
        rm "$fifo"
    }
    read ${1:+-t "$1"} -u $_snore_fd || :
}
#The "snore" function is a way to avoid getting a sleep process, so "snore 1.33" is equivalent to "sleep 1.33"(seconds)
snore 1.33
mem=`free | awk '/Mem/ {printf "%d MB\n", $3 / 1024.0, $2 / 1024.0 }'`
#Please note an "echo" line here allows to be displayed, next to it, more than one line, piled horizontally
echo
#UnComment to show CPU usage (in percetage):
echo "CPU "$[100-$(vmstat 1 2|tail -1|awk '{print $15}')]"%"
#UnComment to show available RAM:
echo "RAM $mem"
