commit fc8323c6eaa8aa7325f1fe30b4d89b76c0d9e03a from: gonzalo date: Thu Jun 04 17:37:01 2020 UTC Add functions and try to keep it simple and clean, hopelly this regex catch ssid names with and without spaces commit - 29bb64853ad4e700d27c1e80612f7df168184395 commit + fc8323c6eaa8aa7325f1fe30b4d89b76c0d9e03a blob - 482e9f3ccb095f6d825dc4b9181092967bac41ed blob + b56e37221d2680a86ccb90cc1417c0389d685250 --- termbar/termbar +++ termbar/termbar @@ -1,25 +1,68 @@ #!/bin/sh -yel='\033[33m' -pur='\033[35m' -gre='\033[32m' -rst='\033[0m' +## Debug +#set -x -pipe="${pur}|${rst}" +esc="\033" +reset="${esc}[0m" +redf="${esc}[31m" +cyanf="${esc}[36m"; +purplef="${esc}[35m" +pipe="${purplef}|${reset}" -while true; do +today() +{ + DATE=$(date +"%B %d - %H:%M") +} + +cpu() +{ CPU_SPEED=$(sysctl hw.cpuspeed | cut -d "=" -f 2 | cut -d "." -f 1) CPU_TEMP=$(sysctl hw.sensors.cpu0.temp0 | cut -d "=" -f 2 | cut -d "." -f 1) - RAM=$(top | grep Memory | awk {'print $6'}) - BAT_STATUS=$(sysctl hw.sensors.acpiac0.indicator0 | cut -d "=" -f 2 | cut -d "." -f 1) +} + +bat() +{ BAT=$(apm -l) - DATE=$(date +"%B %d - %H:%M") - SSID=$(ifconfig | grep ieee | awk -F'"' '$0=$2') -# SSID=$(ifconfig | grep ieee | awk '/join/ {print $3}') - INTIP=$(ifconfig trunk0 | grep inet | awk '{print $2}') - IP=$(dig +short myip.opendns.com @resolver1.opendns.com | awk {'printf $1'}) - printf " $DATE ${pipe} ${gre}CPU:${rst} $CPU_SPEED ($CPU_TEMP°) ${pipe} ${gre}Free Ram:${rst} $RAM " - printf "${pipe} ${gre}Bat:${rst} $BAT - $BAT_STATUS ${pipe} ${gre}SSID:${rst} $SSID ${pipe}" - printf " ${gre}Pub. IP:${rst} $IP - ${gre}Int. IP:${rst} $INTIP \r" - sleep 15 +} + +bat_status() +{ + STATUS=$(sysctl hw.sensors.acpiac0.indicator0 | grep -c On) + + if [ ${STATUS} -eq "1" ]; then + BAT_STATUS=$(echo Connected) + else + BAT_STATUS=$(echo ${redf}Disconnected${reset}) + fi +} + +mem() +{ + MEM=$(top -n | grep Memory | awk {'print $6'}) +} + +wifi() +{ + SSID=$(ifconfig | grep join | sed -e 's/.*join\(.*\)chan.*/\1/') +} + +network() +{ + IIP=$(ifconfig trunk0 | grep inet | awk '{print $2}') + PIP=$(dig +short myip.opendns.com @resolver1.opendns.com | awk {'printf $1'}) +} + +while true; do + today + cpu + mem + bat + bat_status + wifi + network + printf " ${DATE} ${pipe} ${cyanf}CPU:${reset} ${CPU_SPEED} MHz (${CPU_TEMP}°) ${pipe} ${cyanf}Mem:${reset} ${MEM} " + printf "${pipe} ${cyanf}Bat:${reset} $BAT - ${BAT_STATUS} ${pipe} ${cyanf}SSID:${reset}${SSID}${pipe}" + printf " ${cyanf}IPs:${reset} ${PIP} / ${IIP} \v" + sleep 15 done