diff options
author | Justine Smithies <justine@smithies.me.uk> | 2024-11-08 20:48:58 +0000 |
---|---|---|
committer | Justine Smithies <justine@smithies.me.uk> | 2024-11-08 20:48:58 +0000 |
commit | c2fbc4d1717864a0055592e0b73d71c010e8686c (patch) | |
tree | 76e5bf50cc0f9c1b83f474740a8015d7f4e0ef26 /.config/eww/scripts/network.sh | |
parent | b9d24b3b6bdaed04fab07d9150c51d4f0f7a5c7d (diff) |
Initial commit
Diffstat (limited to '.config/eww/scripts/network.sh')
-rwxr-xr-x | .config/eww/scripts/network.sh | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/.config/eww/scripts/network.sh b/.config/eww/scripts/network.sh new file mode 100755 index 0000000..29396aa --- /dev/null +++ b/.config/eww/scripts/network.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# This script requires dnsutils aka bind to fetch the WAN IP address + +# Shows the connections names +# nmcli connection show --active | grep 'ethernet' | awk '{ print $1 }' FS=' ' +# nmcli connection show --active | grep 'wifi' | awk '{ print $1 }' FS=' ' + +# Show ethernet interface name +# nmcli connection show --active | grep 'ethernet' | awk '{ print $6 }' FS=' ' + +# Show wifi interface name +# nmcli connection show --active | grep 'wifi' | awk '{ print $4 }' FS=' ' + +function ShowInfo { + if [ "$(nmcli connection show --active | grep -oh "\w*ethernet\w*")" == "ethernet" ]; then + wan="$(dig @resolver4.opendns.com myip.opendns.com +short)" + connection="$(nmcli connection show --active | grep 'ethernet' | awk '{ print $6 }' FS=' '): $(nmcli connection show --active | grep 'ethernet' | awk '{ printf "%s\nLAN IP:",$1 }' FS=' ') $(nmcli -t -f IP4.ADDRESS dev show $(nmcli connection show --active | grep 'ethernet' | awk '{ print $6 }' FS=' ') | awk '{printf "%s\nWAN IP: '$wan'", $2}' FS='[:/]')" + elif [ "$(nmcli connection show --active | grep -oh "\w*wifi\w*")" == "wifi" ]; then + wan="$(dig @resolver4.opendns.com myip.opendns.com +short)" + connection="$(nmcli connection show --active | grep 'wifi' | awk '{ print $4 }' FS=' '): $(nmcli connection show --active | grep 'wifi' | awk '{ printf "%s\nLAN IP:",$1 }' FS=' ') $(nmcli -t -f IP4.ADDRESS dev show $(nmcli connection show --active | grep 'wifi' | awk '{ print $4 }' FS=' ') | awk '{printf "%s/nWAN IP: '$wan'", $2}' FS='[:/]')" + else + connection="No active connection." + fi + fyi -i "network-idle" --hint string:x-canonical-private-synchronous:network-status "$connection" +} + +function IconUpdate() { + if [ "$(nmcli connection show --active | grep -oh "\w*ethernet\w*")" == "ethernet" ]; then + icon="" + elif [ "$(nmcli connection show --active | grep -oh "\w*wifi\w*")" == "wifi" ]; then + icon="" + else + icon="" + fi + printf "%s" "$icon" +} + +if [ "$1" = "ShowInfo" ]; then + ShowInfo +else + IconUpdate +fi |