diff options
author | Justine Smithies <justine@smithies.me.uk> | 2023-10-11 18:21:52 +0100 |
---|---|---|
committer | Justine Smithies <justine@smithies.me.uk> | 2023-10-11 18:21:52 +0100 |
commit | 786f9c22fab19de866566de4c7933aef416a1462 (patch) | |
tree | 512c3563b43a511171979604d6a2a09a4b68c50a /.config/yambar/scripts/network.sh | |
parent | ba6e0a870faa3306b1e15bd03460b2faa30ceb37 (diff) |
Switched to River
Diffstat (limited to '.config/yambar/scripts/network.sh')
-rwxr-xr-x | .config/yambar/scripts/network.sh | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/.config/yambar/scripts/network.sh b/.config/yambar/scripts/network.sh new file mode 100755 index 0000000..73338f9 --- /dev/null +++ b/.config/yambar/scripts/network.sh @@ -0,0 +1,48 @@ +#!/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 +short myip.opendns.com @resolver1.opendns.com)" + connection="$(nmcli connection show --active | grep 'ethernet' | awk '{ print $6 }' FS=' '): $(nmcli connection show --active | grep 'ethernet' | awk '{ print $1 }' FS=' ') - $(nmcli -t -f IP4.ADDRESS dev show $(nmcli connection show --active | grep 'ethernet' | awk '{ print $6 }' FS=' ') | awk '{print $2}' FS='[:/]') +WAN IP: $wan" + elif [ "$(nmcli connection show --active | grep -oh "\w*wifi\w*")" == "wifi" ]; then + wan="$(dig +short myip.opendns.com @resolver1.opendns.com)" + connection="$(nmcli connection show --active | grep 'wifi' | awk '{ print $4 }' FS=' '): $(nmcli connection show --active | grep 'wifi' | awk '{ print $1 }' FS=' ') - $(nmcli -t -f IP4.ADDRESS dev show $(nmcli connection show --active | grep 'wifi' | awk '{ print $4 }' FS=' ') | awk '{print $2}' FS='[:/]') +WAN IP: $wan" + else + connection="No active connection." + fi +} + +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 +} + +ShowInfo +IconUpdate + +text="$icon" + +tooltip="$(echo "$connection" | sed -z 's/\n/\\n/g')" +tooltip=${tooltip::-2} + +echo "{\"text\":\""$text"\", \"tooltip\":\""$tooltip"\"}" +exit 0 |