summaryrefslogtreecommitdiff
path: root/.local/bin/statusbar/netinfo
blob: 62c3619de55408ffaaff15f20c370ac5c58af523 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env bash

netstatus="$(awk '{
      n = split(FILENAME, a, "/")
      printf("%-15s %s\n", a[n-1], $1)
    }' /sys/class/net/[ew]*/operstate | sort -k 2)"

function add_connected_address() {
  TMPIFS="${IFS}"
  IFS='
'
  for line in $netstatus; do
    device=$(echo $line | awk '{print $1}')
    address=$(ip addr show $device | sed -En 's/inet ([0-9\.]+).*/\1/p')
    # Append Wifi AP if connected
    AP_NAME="$(iwgetid -r)"
    [ -n "${address}" ] && [ -n "${AP_NAME}" ] && address="${address} (${AP_NAME})"
    echo "${line} ${address}"
  done
  IFS="${TMPIFS}"
}

ARG=${1:-$BLOCK_BUTTON}

case $ARG in
	1) notify-send --urgency=low "Internet connection" "$(add_connected_address)" ;;
esac

if [ -z "$(echo -e "${netstatus}" | sed -En '/up$/p' | tr -d '\n')" ]; then
	echo -en '\x0c\uf701'
else
	echo -en '\x0d'
	echo -en $(echo -n "${netstatus}" | sed -En 's/^(w[^ ]+).*up/\\uf1eb/p;s/^(e[^ ]+).*up/\\uf700/p')
fi

echo -en '\x0b'