From: Christian Heller Date: Wed, 19 Mar 2025 23:43:37 +0000 (+0100) Subject: Improve status script. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%22https:/validator.w3.org/todo?a=commitdiff_plain;p=config Improve status script. --- diff --git a/testing/home/t490s/.nonpath_bins/status.sh b/testing/home/t490s/.nonpath_bins/status.sh index 9f21785..ce1a433 100755 --- a/testing/home/t490s/.nonpath_bins/status.sh +++ b/testing/home/t490s/.nonpath_bins/status.sh @@ -23,6 +23,27 @@ print_bar_block() { printf '},\n' } +print_calc() { + printf "%d" $(calc "$1") +} + +color_at() { + IDX=0 + while true; do + IDX=$(print_calc "${IDX} + 1") + STEP=$(echo "$2" | cut -d'_' -f${IDX}) + if [ -z "${STEP}" ]; then + break + fi + LIMIT=$(echo "${STEP}" | cut -d':' -f1) + COLOR=$(echo "${STEP}" | cut -d':' -f2) + if [ "${LIMIT}" -ge "${1}" ]; then + printf "${COLOR}" + break + fi + done +} + print_clipboard() { print_selection() { print_bar_block "$1:[" "${COL_WHITE}" 0 @@ -46,11 +67,18 @@ print_online() { if [ -z "${IP}" ]; then print_bar_block '-' else - print_bar_block "${IP}" "${COL_WHITE}" + print_bar_block "${IP}" "${COL_WHITE}" "$2" fi } print_conn enp - print_conn wlp + print_conn wlp 0 + STATUS_WIFI=$(nmcli -t -f IN-USE,SSID,SIGNAL dev wifi | grep '^\*:') + if [ ! -z "${STATUS_WIFI}" ]; then + SIGNAL=$(echo -n "${STATUS_WIFI}" | cut -d':' -f3) + COLOR=$(color_at $SIGNAL "45:${COL_RED}_85:${COL_YELLOW}_100:${COL_GREEN}") + print_bar_block " ${SIGNAL}" "${COLOR}" 0 + print_bar_block "% $(echo "${STATUS_WIFI}" | cut -d':' -f2)" + fi } print_battery() { @@ -60,16 +88,11 @@ print_battery() { cat_energy() { cat "${BAT_DIR}/energy_$1" } - printf "%d" $(calc "100 * $(cat_energy $1) // $(cat_energy $2)") + print_calc "100 * $(cat_energy $1) // $(cat_energy $2)" } 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 + COLOR=$(color_at $CHARGE "25:${COL_RED}_65:${COL_YELLOW}_100:${COL_GREEN}") print_bar_block "${CHARGE}%" "${COLOR}" 0 COLOR="${COL_WHITE}" @@ -92,12 +115,8 @@ print_battery() { print_temperature() { 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 - COLOR="${COL_RED}" - elif [ $TEMPERATURE_IN_C -gt 65 ]; then - COLOR="${COL_YELLOW}" - fi + TEMPERATURE_IN_C=$(print_calc "${TEMPERATURE} // 1000") + COLOR=$(color_at $TEMPERATURE_IN_C "65:${COL_GREEN}_85:${COL_YELLOW}_999:${COL_RED}") print_bar_block "${TEMPERATURE_IN_C}" "${COLOR}" 0 print_bar_block '°' } @@ -115,7 +134,7 @@ print_volume() { MUTE=M if [ "$(pactl get-sink-mute 0)" = "Mute: no" ]; then MUTE= - COLOR="${COL_WHITE}" + COLOR="${COL_RED}" fi print_bar_block "v:${MUTE}$(pactl get-sink-volume 0 | head -1 | cut -d' ' -f5)" "${COLOR}" } @@ -132,7 +151,7 @@ print_keyboard() { print_bar_block "k:${LAYOUT}" } -printf '{"version": 1}\n[' +printf '{"version": 1}\n[' while true; do printf '[' print_clipboard