[BACK]Return to termbar CVS log [TXT][DIR] Up to [x61] / dotfiles / termbar

File: [x61] / dotfiles / termbar / termbar (download)

Revision 1.5, Mon Jun 8 15:38:24 2020 UTC (19 months, 2 weeks ago) by gonzalo
Branch: MAIN
Changes since 1.4: +1 -1 lines

Fix the -fg of termbar and fix a typo on the bar

#!/bin/sh

## Debug
#set -x

esc="\033"
reset="${esc}[0m"
redf="${esc}[31m"
cyanf="${esc}[36m";
purplef="${esc}[35m"
pipe="${purplef}|${reset}"

today()
{
	DATE=$(date +"%B %d - %H:%M")
}

cpu()
{
	CPU_TEMP=$(sysctl hw.sensors.cpu0.temp0 | cut -d "=" -f 2 | cut -d "." -f 1)
	CPU_SPEED=$(printf "%4s" $(sysctl hw.cpuspeed | cut -d "=" -f 2 | cut -d "." -f 1))
}

bat()
{
	BAT=$(apm -l)
}

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} \r"
        sleep 15
done