|
|
@ -1,16 +1,85 @@ |
|
|
|
#!/bin/sh |
|
|
|
#!/bin/sh |
|
|
|
# Usage: ./netinfo.sh [--color [screen]] |
|
|
|
# Usage: ./netinfo.sh [--color [screen]] |
|
|
|
|
|
|
|
|
|
|
|
if [ "$1" = "--color" ]; then |
|
|
|
while [ $# -gt 0 ] ; do |
|
|
|
case $2 in |
|
|
|
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") |
|
|
|
"screen") |
|
|
|
colgreen="\005{g}" |
|
|
|
shift |
|
|
|
colyellow="\005{y}" |
|
|
|
colorize=1 |
|
|
|
colred="\005{r}" |
|
|
|
colgreen="\005{g}" |
|
|
|
colred_blink="\005{+B r}" |
|
|
|
colyellow="\005{y}" |
|
|
|
colend="\005{-}" |
|
|
|
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" |
|
|
|
colgreen="\033[0;32m" |
|
|
|
colyellow="\033[0;33m" |
|
|
|
colyellow="\033[0;33m" |
|
|
|
colred="\033[0;31m" |
|
|
|
colred="\033[0;31m" |
|
|
@ -18,31 +87,42 @@ if [ "$1" = "--color" ]; then |
|
|
|
colend="\033[0m" |
|
|
|
colend="\033[0m" |
|
|
|
;; |
|
|
|
;; |
|
|
|
*) |
|
|
|
*) |
|
|
|
printf "Color coding not supported. Aborting...\n" |
|
|
|
printf "Color coding not supported. Aborting...\n" |
|
|
|
exit 1 |
|
|
|
exit 1 |
|
|
|
;; |
|
|
|
;; |
|
|
|
esac |
|
|
|
esac |
|
|
|
fi |
|
|
|
;; |
|
|
|
|
|
|
|
*) |
|
|
|
|
|
|
|
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 '.')" |
|
|
|
wifi_signal="$(cat < /proc/net/wireless | grep "$1" | awk '{print $3}' | tr -d '.')" |
|
|
|
bar="" |
|
|
|
bar="" |
|
|
|
case $wifi_signal in |
|
|
|
case $wifi_signal in |
|
|
|
[0-1][0-9]) |
|
|
|
[0][0-9]) |
|
|
|
color=${colred} |
|
|
|
color=${colred} |
|
|
|
bar="▂___" |
|
|
|
bar="$iconbar0" |
|
|
|
|
|
|
|
;; |
|
|
|
|
|
|
|
[1][0-9]) |
|
|
|
|
|
|
|
color=${colred} |
|
|
|
|
|
|
|
bar="$iconbar1" |
|
|
|
;; |
|
|
|
;; |
|
|
|
[2-3][0-9]) |
|
|
|
[2-3][0-9]) |
|
|
|
color=${colyellow} |
|
|
|
color=${colyellow} |
|
|
|
bar="▂▄__" |
|
|
|
bar="$iconbar2" |
|
|
|
;; |
|
|
|
;; |
|
|
|
[4-5][0-9]) |
|
|
|
[4-5][0-9]) |
|
|
|
color=${colgreen} |
|
|
|
color=${colgreen} |
|
|
|
bar="▂▄▆_" |
|
|
|
bar="$iconbar3" |
|
|
|
;; |
|
|
|
;; |
|
|
|
[6-7][0-9]) |
|
|
|
[6-7][0-9]) |
|
|
|
color=${colgreen} |
|
|
|
color=${colgreen} |
|
|
|
bar="▂▄▆█" |
|
|
|
bar="$iconbar4" |
|
|
|
;; |
|
|
|
;; |
|
|
|
*) |
|
|
|
*) |
|
|
|
color=${colred_blink} |
|
|
|
color=${colred_blink} |
|
|
@ -57,13 +137,13 @@ IFACES="$(ip link show | awk '/^[0-9]+:/ {sub(/:/,"",$2); print $2","$9}')" |
|
|
|
multi_ifce=0 |
|
|
|
multi_ifce=0 |
|
|
|
for NET_IFACE in $IFACES ; do |
|
|
|
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)" |
|
|
|
device="$(echo "$NET_IFACE" | cut -d ',' -f1)" |
|
|
|
case $device in |
|
|
|
case $device in |
|
|
|
wlp*) |
|
|
|
wlp*) |
|
|
|
[ $multi_ifce = 1 ] && STR_OUT="$STR_OUT|" || multi_ifce="1" |
|
|
|
[ $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*) |
|
|
|
enp*) |
|
|
|
[ $multi_ifce = 1 ] && STR_OUT="$STR_OUT|" || multi_ifce="1" |
|
|
|
[ $multi_ifce = 1 ] && STR_OUT="$STR_OUT|" || multi_ifce="1" |
|
|
@ -77,3 +157,5 @@ for NET_IFACE in $IFACES ; do |
|
|
|
done |
|
|
|
done |
|
|
|
|
|
|
|
|
|
|
|
printf "%s" "${STR_OUT}" |
|
|
|
printf "%s" "${STR_OUT}" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ "$newline" = 1 ] && printf "\n" || : |
|
|
|