From eaf856b0bc3693256eb90ed000ff828dbaf99203 Mon Sep 17 00:00:00 2001 From: meliurwen Date: Thu, 28 Jul 2022 13:40:20 +0200 Subject: [PATCH] screen: expanded netinfo script printing capabilities --- screen/.config/screen/bin/netinfo.sh | 122 ++++++++++++++++++++++----- screen/.screenrc | 2 +- 2 files changed, 103 insertions(+), 21 deletions(-) diff --git a/screen/.config/screen/bin/netinfo.sh b/screen/.config/screen/bin/netinfo.sh index 2c6e82a..735c533 100755 --- a/screen/.config/screen/bin/netinfo.sh +++ b/screen/.config/screen/bin/netinfo.sh @@ -1,16 +1,85 @@ #!/bin/sh # Usage: ./netinfo.sh [--color [screen]] -if [ "$1" = "--color" ]; then - case $2 in +while [ $# -gt 0 ] ; do + case "$1" in + "--newline") + newline=1 + ;; + "--icon") + case $2 in + "ascii"|""|"--"*) + case "$2" in + "--"*|"") + : # skip if it's a parameter or is empty + ;; + *) + shift + ;; + esac + iconize=1 + iconbar0="[----]" + iconbar1="[#---]" + iconbar2="[##--]" + iconbar3="[###-]" + iconbar4="[####]" + ;; + "ascii-alt") + shift + iconize=1 + iconbar0="____" + iconbar1="▂___" + iconbar2="▂▄__" + iconbar3="▂▄▆_" + iconbar4="▂▄▆█" + ;; + "nerd") + shift + iconize=1 + iconbar0= + iconbar1= + iconbar2= + iconbar3= + iconbar4= + ;; + *) + printf "Icon coding not supported. Aborting...\n" + exit 1 + ;; + esac + ;; + "--color") + case $2 in "screen") - colgreen="\005{g}" - colyellow="\005{y}" - colred="\005{r}" - colred_blink="\005{+B r}" - colend="\005{-}" + shift + colorize=1 + colgreen="\005{g}" + colyellow="\005{y}" + colred="\005{r}" + colred_blink="\005{+B r}" + colend="\005{-}" ;; - "") + "lemonbar") + shift + colorize=1 + # xterm ANSI color palette + colgreen="%{F#00CD00}" + colyellow="%{F#CDCD00}" + colred="%{F#CD0000}" + colred_blink="%{F#000000}%{B#CD0000}" # no blinking available :( + colend="%{F-}" + colbgend="%{B-}" + ;; + "ansi"|""|"--"*) + case "$2" in + "--"*|"") + : # skip if it's a parameter or is empty + ;; + *) + shift + ;; + esac + colorize=1 colgreen="\033[0;32m" colyellow="\033[0;33m" colred="\033[0;31m" @@ -18,31 +87,42 @@ if [ "$1" = "--color" ]; then colend="\033[0m" ;; *) - printf "Color coding not supported. Aborting...\n" - exit 1 + printf "Color coding not supported. Aborting...\n" + exit 1 ;; - esac -fi + esac + ;; + *) + printf "Parameter not recognized. Aborting...\n" + exit 1 + ;; + esac + shift +done -wifi_str() { +_wifi_str() { wifi_signal="$(cat < /proc/net/wireless | grep "$1" | awk '{print $3}' | tr -d '.')" bar="" case $wifi_signal in - [0-1][0-9]) + [0][0-9]) color=${colred} - bar="▂___" + bar="$iconbar0" + ;; + [1][0-9]) + color=${colred} + bar="$iconbar1" ;; [2-3][0-9]) color=${colyellow} - bar="▂▄__" + bar="$iconbar2" ;; [4-5][0-9]) color=${colgreen} - bar="▂▄▆_" + bar="$iconbar3" ;; [6-7][0-9]) color=${colgreen} - bar="▂▄▆█" + bar="$iconbar4" ;; *) color=${colred_blink} @@ -57,13 +137,13 @@ IFACES="$(ip link show | awk '/^[0-9]+:/ {sub(/:/,"",$2); print $2","$9}')" multi_ifce=0 for NET_IFACE in $IFACES ; do - [ "$(echo "$NET_IFACE" | cut -d ',' -f2)" = "DOWN" ] && continue + [ "$(printf "%s\n" "$NET_IFACE" | cut -d ',' -f2)" = "DOWN" ] && continue device="$(echo "$NET_IFACE" | cut -d ',' -f1)" case $device in wlp*) [ $multi_ifce = 1 ] && STR_OUT="$STR_OUT|" || multi_ifce="1" - STR_OUT="$STR_OUT$(wifi_str "$device")" + STR_OUT="$STR_OUT$(_wifi_str "$device")" ;; enp*) [ $multi_ifce = 1 ] && STR_OUT="$STR_OUT|" || multi_ifce="1" @@ -77,3 +157,5 @@ for NET_IFACE in $IFACES ; do done printf "%s" "${STR_OUT}" + +[ "$newline" = 1 ] && printf "\n" || : diff --git a/screen/.screenrc b/screen/.screenrc index 24ddb4e..e7c4210 100755 --- a/screen/.screenrc +++ b/screen/.screenrc @@ -16,7 +16,7 @@ defscrollback 10000 # backtick id lifespan autorefresh cmd args... backtick 1 10 10 $HOME/.config/screen/bin/battery.sh --color screen -backtick 2 10 10 $HOME/.config/screen/bin/netinfo.sh --color screen +backtick 2 10 10 $HOME/.config/screen/bin/netinfo.sh --icon ascii --color screen # Statusbar hardstatus on