#!/bin/bash

OUTPUT="$(ip -br link | awk '{print $1, $2}' | grep UP| awk '{print $1}')"

# echo "$OUTPUT"

ITYPES=()
IFACES=()

for IFACE in $OUTPUT; do
    case $IFACE in
        en*|eth*) TYPE="Ethernet" ;;
        wl*|wlan*) TYPE="Wi-Fi" ;;
        *) TYPE="Unknown" ;;
    esac
    ITYPES+=("$TYPE")
    IFACES+=("$IFACE")
done

if printf "%s\n" "${ITYPES[@]}" | grep -qx "Ethernet"; then
    echo "󰈀 "
elif printf "%s\n" "${ITYPES[@]}" | grep -qx "Wi-Fi"; then
    if [ -x "/usr/bin/nmcli" ]; then
        CONNECTION="$(nmcli -f DEVICE,ACTIVE,SSID,SIGNAL dev wifi | grep yes | awk '{print $NF}')"
        if [[ -z "$CONNECTION" ]]; then
            echo "󰤭 "
        elif (( CONNECTION > 80 )); then
            echo "󰤨 "
        elif (( CONNECTION > 60 )); then
            echo "󰤥 "
        elif (( CONNECTION > 40 )); then
            echo "󰤢 "
        elif (( CONNECTION > 20 )); then
            echo "󰤟 "
        else
            echo "󰤯 "
        fi
    else
        echo "󰤩 "
    fi
else
    echo "󰤭 /󱐤 "
fi