#!/bin/sh DEFAULT_COLOR="#cccccc" STATUS_WELL_COLOR="#31f53e" STATUS_OK_COLOR="#f58c31" STATUS_UNWELL_COLOR="#f53131" BATTERY_NAME="BAT1" BATTERY_EMPTY_THRESHOLD=20 BATTERY_FULL_THRESHOLD=80 WIFI_ADAPTER="wlan0" DISK_ICON_COLOR="#48a3e8" SSID_HIDE_FILE="/tmp/monitors_no-ssid" readable_kib() { data="$1" decimals="$2" if [ "$data" -lt 1024 ]; then amt="$1" letter="K" elif [ "$data" -lt 1048576 ]; then amt="$(($1 / 1024))" letter="M" else amt="$(($1 / 1048576))" letter="G" fi printf "%.*f%s\n" "$decimals" "$amt" "$letter" } monitor_battery() { read -r capacity %s%% (%s)\n' "$icon" "$color" "$capacity" "$status" } monitor_cpu() { while read -r line; do case "$line" in *"Package id 0:"*) temp="${line#Package id 0:*+}" temp="${temp%%°*}" temp="${temp%.*}" break ;; esac done <%s' "$color" "$load" [ "$i" -ne 2 ] && printf ' ' i=$((i + 1)) done printf '\n' done %s%%)\n' "$(readable_kib "$used_mem" 1)" "$color" "$usage_percent" } monitor_ssid() { if [ -f "$SSID_HIDE_FILE" ]; then while IFS= read -r line; do hidden_ssid="$line" done <"$SSID_HIDE_FILE" fi while IFS= read -r line; do case "$line" in *"Connected network"*) [ ! -f "$SSID_HIDE_FILE" ] && ssid="$line" || ssid="$hidden_ssid" ;; esac done <%s%%\n' "$icon" "$color" "$volume" } monitor_uptime() { up="$(uptime -p)" up="${up#up }" while :; do case "$up" in *","*) up="${up%%,*}${up#*,}" ;; *) break ;; esac done while :; do case "$up" in *\ days*) up="${up%% days*}d${up#* days}" ;; *\ day*) up="${up%% day*}d${up#* day}" ;; *\ hours*) up="${up%% hours*}h${up#* hours}" ;; *\ hour*) up="${up%% hour*}h${up#* hour}" ;; *\ minutes*) up="${up%% minutes*}m${up#* minutes}" ;; *\ minute*) up="${up%% minute*}h${up#* minute}" ;; *) break ;; esac done printf '%s\n' "$up" } monitor_disk() { disk="${2:-}" use_icon="${3:-}" [ -z "$disk" ] || [ ! -d "$disk" ] && exit 1 if [ -n "$use_icon" ]; then case "$disk" in /) icon="" ;; /home) icon="" ;; *) icon="" ;; esac else case "$disk" in /home) icon="~" ;; *) icon="$disk" ;; esac fi i=0 while read -r _ size used _; do case "$i" in 0) ;; 1) size_amt="$size" used_amt="$used" ;; *) break ;; esac i=$((i + 1)) done <%s %s/%s (%s%%)\n' "$DISK_ICON_COLOR" "$icon" "$(readable_kib "$used_amt" 0)" "$(readable_kib "$size_amt" 0)" "$STATUS_WELL_COLOR" "$((used_amt * 100 / size_amt))" } monitor_service() { service="$2" status="$(sv status "$service")" || exit 1 status="${status%:*:*}" case "$status" in run) icon="" color="$STATUS_WELL_COLOR" ;; down) icon="" color="$STATUS_UNWELL_COLOR" ;; esac printf '%s %s\n' "$color" "$icon" "$service" } if command -v monitor_"$1" >/dev/null 2>&1; then monitor_"$1" "$@" else exit 1 fi