dotfiles/scripts/status/netstat
2024-07-11 12:00:51 -06:00

48 lines
1.3 KiB
Bash
Executable file

#!/bin/sh
int() { # Type of interface & status
# If active ethernet, just exit with icon
grep -xq 'up' /sys/class/net/e*/operstate 2>/dev/null && echo "󰛳" && return 0
# If active WiFi, print link strength
if grep -xq 'up' /sys/class/net/w*/operstate 2>/dev/null ; then
strength="$(awk 'NR==3 {printf("%.0f\n",$3*10/7)}' /proc/net/wireless)"
case 1 in
$((strength >= 85)) ) icon="󰤨" ;;
$((strength >= 65)) ) icon="󰤥" ;;
$((strength >= 45)) ) icon="󰤢" ;;
$((strength >= 25)) ) icon="󰤟" ;;
$((strength >= 0)) ) icon="󰤯" ;;
esac
echo "$icon"
return 0
fi
# If down interfaces, exit with icon
grep -xq 'down' /sys/class/net/w*/operstate 2>/dev/null && echo "󰤮" && return 0
grep -xq 'down' /sys/class/net/e*/operstate 2>/dev/null && echo "󰲛" && return 0
}
# Run 'int'
icon=$(int)
# Check if a VPN is enabled
vpn="$( \
sed "s/.*//" /sys/class/net/tun*/operstate 2>/dev/null
sed "s/.*//" /sys/class/net/wg*/operstate 2>/dev/null \
)"
# If so, change icon
if [ -n "$vpn" ] ; then
icon="$(printf '%s' "$icon" | sed '
s/󰤨/󰤪/;
s/󰤥/󰤧/;
s/󰤢/󰤤/;
s/󰤟/󰤡/;
s/󰤯/󰤬/;
')"
fi
# Print $info
printf "%s" "$icon"