#!/bin/bash div="%{F#0092ff}<>%{F-}%{B-}" # Global var, last epoch time we checked email # Update this when we call email() so that we can # call email() every second, but only call himalaya # once every minute LAST_EMAIL_CHECK_EPOCH=$(date +%s) EMAIL_STATE="Email: No new emails" email() { EPOCH_NOW=$(date +%s) DIFF=$((EPOCH_NOW - $LAST_EMAIL_CHECK_EPOCH)) if [ $DIFF -gt 60 ]; then NEW_EMAILS=$(himalaya list -s 1 | grep ✷ | wc -l) if [ $NEW_EMAILS -gt 0 ]; then EMAIL_STATE="Email: ** New Emails **" LAST_EMAIL_CHECK_EPOCH=$(date +%s) else EMAIL_STATE="Email: No new emails" fi fi echo -n "$EMAIL_STATE" echo -n " Last Checked: $LAST_EMAIL_CHECK_EPOCH " } Clock() { DATETIME=$(date "+%a %b %d, %T") echo -n "$DATETIME" } cpuTemp() { CPUTEMP=$(sensors | grep CPU | awk '{print $2}') echo -n "CPU Temp: $CPUTEMP" } batteryInfo() { capacityRemaining=$(cat /sys/class/power_supply/BAT0/capacity) batteryStatus=$(cat /sys/class/power_supply/BAT0/status) if [[ $capacityRemaining -lt 25 ]]; then capacityRemaining="%{F#ff5b00}$capacityRemaining %{F-}%{B-}" fi if [[ "$batteryStatus" == "Charging" ]]; then batteryStatus="%{F#ff9966}$batteryStatus%{F-}%{B-}" fi capacityRemaining=$capacityRemaining% echo -n "Battery: $capacityRemaining $batteryStatus" } wifiInfo() { connectionName=$(wpa_cli status | egrep "^ssid" | sed s/ssid=//g) ipAddr=$(wpa_cli status | egrep "^ip" | sed s/ip_address=//g) echo -n "Wifi: $connectionName $div IP: $ipAddr" } ethPort() { linkDetected=$(cat /sys/class/net/enp0s31f6/carrier) if [[ $linkDetected -eq 0 ]]; then connected="eth0: down" elif [[ $linkDetected -eq 1 ]]; then connected="eth0: up" fi echo -n "$connected" } diskFree() { freeNVME=$(df -h /dev/mapper/decryptedRoot-root | awk '{print $4}' | tail -n1) echo -n "NVMe Free: $freeNVME" } loadAvg() { la=$(uptime | grep -o :\ [0-9].* | sed s/://g | awk '{print $1}' | sed s/,//g) if (( $(echo "$la > 8" |bc -l) )); then la="%{F#ff5b00}$la%{F-}%{B-}" else la="%{F#ff9966}$la%{F-}%{B-}" fi echo -n "Load: $la" } soundState() { muted=$(pactl list sinks | grep Mute: | awk '{print $2}') if [[ "$muted" == yes ]]; then state="Volume: 0%" else level=$(pactl list sinks | grep Volume: | awk '{print $5}' | head -n1) state="Volume: $level" fi echo -n $state } while true; do sleep 1 echo "%{l} $(Clock) $div $(cpuTemp) $div $(loadAvg) $div $(wifiInfo) $div $(ethPort) $div $(diskFree) $div $(soundState) $div $(batteryInfo) $div $(email)" sleep 0.5 done