From 37fdde76c888645c3e6f3c1147987c2fddb0b114 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Mon, 17 Mar 2025 23:20:38 +0100 Subject: [PATCH] Improve status script; --- testing/home/t490s/.nonpath_bins/status.sh | 45 +++++++++++----------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/testing/home/t490s/.nonpath_bins/status.sh b/testing/home/t490s/.nonpath_bins/status.sh index 8822b21..b6fddc9 100755 --- a/testing/home/t490s/.nonpath_bins/status.sh +++ b/testing/home/t490s/.nonpath_bins/status.sh @@ -11,9 +11,11 @@ COL_GREY=aaaaaa print_bar_block() { printf '{"full_text": "%s", ' "$1" + COLOR="${COL_GREY}" if [ ! -z "$2" ]; then - printf '"color": "%s", ' "$2" + COLOR="$2" fi + printf '"color": "%s", ' "${COLOR}" if [ "$3" = "0" ]; then printf '"separator": false,\n' printf '"separator_block_width": 0,' @@ -23,14 +25,13 @@ print_bar_block() { print_online() { print_conn() { - print_bar_block "$(echo $1 | cut -c1):" "${COL_GREY}" 0 - COLOR="${COL_GREEN}" + print_bar_block "$(echo $1 | cut -c1):" "" 0 IP=$(ip --brief addr show | grep "$1" | sed -E 's/ +/\t/g' | cut -f3 | cut -f1 -d'/') if [ -z "${IP}" ]; then - IP='-' - COLOR="${COL_GREY}" + print_bar_block '-' + else + print_bar_block "${IP}" "${COL_WHITE}" fi - print_bar_block "${IP}" "${COLOR}" } print_conn enp print_conn wlp @@ -39,21 +40,21 @@ print_online() { print_battery() { BAT_DIR="${SYSCLASS_DIR}/power_supply/BAT0" - print_percent() { + calc_percent () { cat_energy() { cat "${BAT_DIR}/energy_$1" } - PERCENT=$(printf "%d" $(calc "100 * $(cat_energy $1) // $(cat_energy $2)")) - COLOR="${COL_GREEN}" - if [ "${PERCENT}" -lt 25 ]; then - COLOR="${COL_RED}" - elif [ "${PERCENT}" -lt 65 ]; then - COLOR="${COL_YELLOW}" - fi - print_bar_block "${PERCENT}" "${COLOR}" "$3" + printf "%d" $(calc "100 * $(cat_energy $1) // $(cat_energy $2)") } - print_percent now full 0 + CHARGE=$(calc_percent now full) + COLOR="${COL_GREEN}" + if [ "${CHARGE}" -lt 25 ]; then + COLOR="${COL_RED}" + elif [ "${CHARGE}" -lt 65 ]; then + COLOR="${COL_YELLOW}" + fi + print_bar_block "${CHARGE}" "${COLOR}" 0 COLOR="${COL_WHITE}" STATUS=$(cat "${BAT_DIR}/status") @@ -69,11 +70,11 @@ print_battery() { fi print_bar_block "${CHARGING}" "${COLOR}" 0 - print_percent full full_design + print_bar_block "$(calc_percent full full_design)" } print_temperature() { - COLOR="${COL_GREEN}" + COLOR="${COL_WHITE}" TEMPERATURE=$(cat ${SYSCLASS_DIR}/thermal/thermal_zone0/temp) TEMPERATURE_IN_C=$(printf "%d" $(calc "${TEMPERATURE} // 1000")) if [ $TEMPERATURE_IN_C -gt 85 ]; then @@ -82,16 +83,16 @@ print_temperature() { COLOR="${COL_YELLOW}" fi print_bar_block "${TEMPERATURE_IN_C}" "${COLOR}" 0 - print_bar_block '°C' "${COL_GREY}" + print_bar_block '°' } print_datetime() { DATE=$(date +'%Y-%m-%d') TIME=$(date +'%H:%M:%S') TZ=$(date +'/%Z') - print_bar_block "${DATE} " "${COL_GREY}" 0 - print_bar_block "${TIME}" "" 0 - print_bar_block "${TZ}" "${COL_GREY}" 0 + print_bar_block "${DATE} " "" 0 + print_bar_block "${TIME}" "${COL_WHITE}" 0 + print_bar_block "${TZ}" "" 0 } printf '{"version": 1}\n[' -- 2.30.2