Configuration_Files/misc/bar.sh

46 lines
1.5 KiB
Bash
Executable File

#!/bin/sh -e
FXDE_DIR=/home/midfavila/.config/fxde
tme() #Display current time in 24h notation
{
date|sed -ne 's/ */ /gp'|cut -d ' ' -f4|sed -ne 's/\([0-9][0-9]\):\([0-9][0-9]\).*/\1\2/p'
}
pwr() #Display current battery capacity and whether we're discharging or not.
{
x=$(cat /sys/class/power_supply/BAT1/status)
if [ "${x}" = "Discharging" ]
then printf "%s%%--" "$(cat /sys/class/power_supply/BAT1/capacity)"
else printf "%s%%++" "$(cat /sys/class/power_supply/BAT1/capacity)"
fi
}
ip() #Acquire the IP of our current connection. This is awful. I'm so sorry.
{
x=$(ifconfig wlp2s0|sed -ne 's/.*addr:\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*/\1/p')
if [ "${x}" ]
then printf "%s" "${x}"
else printf "N/A"
fi
}
tmp() #Acquire ambient temperature from wttr.in every ival seconds
{
ival=120 #How often do we check?
if [ "${ival}" = $((ival-($(date|cut -d ':' -f 2)*60)%ival)) ] && \
[ ! -e "${FXDE_DIR}/fxde-core/info/timepiece" ]
then curl -s http://wttr.in/?format=3|\
sed -ne 's/.*\(.[0-9][0-9]*.C\)/\1/p' > "${FXDE_DIR}/fxde-core/info/temp"
touch "${FXDE_DIR}/fxde-core/info/timepiece"
elif [ -e "${FXDE_DIR}/fxde-core/info/timepiece" ] && \
[ "${ival}" != $((ival-($(date|cut -d ':' -f 2)*60)%ival)) ]
then rm "${FXDE_DIR}/fxde-core/info/timepiece"
else cat "${FXDE_DIR}/fxde-core/info/temp"
fi
}
while true;do printf "%%{l}[ %s | %s | %s | %s ]\n" "$(tme)" "$(pwr)" "$(ip)" "$(tmp)";sleep 1;done