Skip to content

Instantly share code, notes, and snippets.

@nekudo
Created June 22, 2020 16:18
Show Gist options
  • Save nekudo/ca5179cd40540772db194c642688a833 to your computer and use it in GitHub Desktop.
Save nekudo/ca5179cd40540772db194c642688a833 to your computer and use it in GitHub Desktop.
GenMon Scripts
#!/usr/bin/env bash
# Makes the script more portable
readonly DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
read -r cpu a b c previdle rest < /proc/stat
prevtotal=$((a+b+c+previdle))
sleep 0.5
read -r cpu a b c idle rest < /proc/stat
total=$((a+b+c+idle))
cpu=$((100*( (total-prevtotal) - (idle-previdle) ) / (total-prevtotal) ))
# Panel
INFO="<txt>"
INFO+="<span font_desc='Ubuntu Mono Regular 12' fgcolor='#5e81ac'>CPU: </span>"
INFO+="<span font_desc='Ubuntu Mono Regular 12' fgcolor='#eceff4'>"
INFO+="${cpu}% | "
INFO+="</span>"
INFO+="</txt>"
# Panel Print
echo -e "${INFO}"
#!/usr/bin/env bash
# Makes the script more portable
readonly DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
read -r cpu a b c previdle rest < /proc/stat
prevtotal=$((a+b+c+previdle))
sleep 0.5
read -r cpu a b c idle rest < /proc/stat
total=$((a+b+c+idle))
cpu=$((100*( (total-prevtotal) - (idle-previdle) ) / (total-prevtotal) ))
# Panel
INFO="<txt>"
INFO+="<span font_desc='Ubuntu Mono Regular 12' fgcolor='#5e81ac'>CPU: </span>"
INFO+="<span font_desc='Ubuntu Mono Regular 12' fgcolor='#eceff4'>"
INFO+="${cpu}% | "
INFO+="</span>"
INFO+="</txt>"
# Panel Print
echo -e "${INFO}"
#!/usr/bin/env bash
# Dependencies: bash>=3.2, coreutils, file, gawk
# Makes the script more portable
readonly DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Calculate RAM values
readonly TOTAL=$(free -b | awk '/^[Mm]em/{$2 = $2 / 1073741824; printf "%.2f", $2}')
readonly USED=$(free -b | awk '/^[Mm]em/{$3 = $3 / 1073741824; printf "%.2f", $3}')
readonly FREE=$(free -b | awk '/^[Mm]em/{$4 = $4 / 1073741824; printf "%.2f", $4}')
readonly SHARED=$(free -b | awk '/^[Mm]em/{$5 = $5 / 1073741824; printf "%.2f", $5}')
readonly CACHED=$(free -b | awk '/^[Mm]em/{$6 = $6 / 1073741824; printf "%.2f", $6}')
readonly AVAILABLE=$(free -b | awk '/^[Mm]em/{$7 = $7 / 1073741824; printf "%.2f", $7}')
# Swap Values
readonly SWP_TOTAL=$(free -b | awk '/^[Ss]wap/{$2 = $2 / 1073741824; printf "%.2f", $2}')
readonly SWP_USED=$(free -b | awk '/^[Ss]wap/{$3 = $3 / 1073741824; printf "%.2f", $3}')
readonly SWP_FREE=$(free -b | awk '/^[Ss]wap/{$4 = $4 / 1073741824; printf "%.2f", $4}')
# Panel
INFO="<txt>"
INFO+="<span font_desc='Ubuntu Mono Regular 12' fgcolor='#5e81ac'>MEM: </span>"
INFO+="<span font_desc='Ubuntu Mono Regular 12' fgcolor='#eceff4'>"
INFO+="${USED}"
INFO+=" / "
INFO+="${TOTAL} GB | "
INFO+="</span>"
INFO+="</txt>"
# Tooltip
MORE_INFO="<tool><span font_desc='Ubuntu Mono Regular 12'>"
MORE_INFO+="┌ RAM\n"
MORE_INFO+="├─ Used\t\t${USED} GB\n"
MORE_INFO+="├─ Free\t\t${FREE} GB\n"
MORE_INFO+="├─ Shared\t${SHARED} GB\n"
MORE_INFO+="├─ Cache\t${CACHED} GB\n"
MORE_INFO+="└─ Total\t${TOTAL} GB"
MORE_INFO+="\n\n"
MORE_INFO+="┌ SWAP\n"
MORE_INFO+="├─ Used\t\t${SWP_USED} GB\n"
MORE_INFO+="├─ Free\t\t${SWP_FREE} GB\n"
MORE_INFO+="└─ Total\t${SWP_TOTAL} GB"
MORE_INFO+="</span></tool>"
# Panel Print
echo -e "${INFO}"
# Tooltip Print
echo -e "${MORE_INFO}"
#!/usr/bin/env bash
# Makes the script more portable
readonly DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WEATHER_XML=$(curl -s https://www.yr.no/place/Germany/North_Rhine-Westphalia/Cologne/forecast.xml)
CUR_NAME=$(echo $WEATHER_XML | xmllint --xpath '//weatherdata/forecast/tabular/time[1]/symbol' - | awk -F '"' '{print $6}')
CUR_TEMP=$(echo $WEATHER_XML | xmllint --xpath '//weatherdata/forecast/tabular/time[1]/temperature' - | awk -F '"' '{print $4}')
NEXT_NAME=$(echo $WEATHER_XML | xmllint --xpath '//weatherdata/forecast/tabular/time[5]/symbol' - | awk -F '"' '{print $6}')
NEXT_TEMP=$(echo $WEATHER_XML | xmllint --xpath '//weatherdata/forecast/tabular/time[5]/temperature' - | awk -F '"' '{print $4}')
TODAY=$(date +%^a)
TOMORROW=$(date -d +1day +%^a)
# Panel
INFO="<txt>"
INFO+="<span font_desc='Ubuntu Mono Regular 12' fgcolor='#5e81ac'>${TODAY}: </span>"
INFO+="<span font_desc='Ubuntu Mono Regular 12' fgcolor='#eceff4'>"
INFO+="${CUR_TEMP}° ${CUR_NAME} "
INFO+="</span>"
INFO+="<span font_desc='Ubuntu Mono Regular 12' fgcolor='#5e81ac'>${TOMORROW}: </span>"
INFO+="<span font_desc='Ubuntu Mono Regular 12' fgcolor='#eceff4'>"
INFO+="${NEXT_TEMP}° ${NEXT_NAME}"
INFO+="</span>"
INFO+="</txt>"
# Panel Print
echo -e "${INFO}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment