#!/bin/sh NOW=$(date +%s) debounce () { local -n VAR_REFERENCE=$1 # Funky Bash Pass-by-reference here! VAR_NAME="$1" DEBOUNCE_TIME="$2" # In Seconds FUNCTION=$3 FALLBACK=$4 if [ ! -f "/tmp/debounce-$VAR_NAME" ]; then VAR_REFERENCE="$FUNCTION" echo "$(date +%s)" > "/tmp/debounce-$VAR_NAME" else LAST_CHECK=$(cat "/tmp/debounce-$VAR_NAME") if [ $(($NOW - $LAST_CHECK)) -gt $DEBOUNCE_TIME ]; then VAR_REFERENCE="$FUNCTION" echo "$(date +%s)" > "/tmp/debounce-$VAR_NAME" else VAR_REFERENCE="$FALLBACK" fi fi } get_mouse_text () { MOUSE_DETAILS=$(rivalcfg --battery-level) MOUSE_STATUS=$(echo $MOUSE_DETAILS | cut -d' ' -f1) MOUSE_BATTERY=$(echo $MOUSE_DETAILS | cut -d']' -f2 | tr -d '[:space:]') if [ "$MOUSE_STATUS" != 'Discharging' ] && [ "$MOUSE_STATUS" != 'Charging' ]; then cat /tmp/last-mouse-level else if [ $MOUSE_STATUS == 'Discharging' ]; then MOUSE_STATUS_EMOJI='🐁' else MOUSE_STATUS_EMOJI='⚡' fi echo "$MOUSE_STATUS_EMOJI $MOUSE_BATTERY" > /tmp/last-mouse-level cat /tmp/last-mouse-level fi } get_monero_text () { MONERO_DETAILS=$(monerod status | grep "Height") MONERO_PERCENT=$(echo $MONERO_DETAILS | cut -d" " -f3 | tr -d "()") if [ -n "$MONERO_DETAILS" ]; then echo "🟢 $MONERO_PERCENT" > /tmp/last-monero-value else echo "🔴" > /tmp/last-monero-value fi cat /tmp/last-monero-value } get_date () { date +%a" "%d" "%b" "%I:%M" "%P > /tmp/last-date cat /tmp/last-date } get_temps () { TEMP=$(sensors | grep Tctl | cut -d"+" -f 2 | cut -d"." -f 1) echo "$TEMP°C" > /tmp/last-temp cat /tmp/last-temp } debounce MOUSE_STRING 3600 \ "$(get_mouse_text)" \ "$(cat /tmp/last-mouse-level || get_mouse_text)"; debounce MONERO_STRING 60 \ "$(get_monero_text)" \ "$(cat /tmp/last-monero-value || get_monero_text)"; debounce DATE_STRING 5 \ "$(get_date)" \ "$(cat /tmp/last-date || get_date)"; debounce TEMP_STRING 5 \ "$(get_temps)" \ "$(cat /tmp/last-temp || get_temps)" echo " $TEMP_STRING | $MOUSE_STRING | $MONERO_STRING | $DATE_STRING"