~tardypad/dotfiles

ref: 7dd5e02494e2821ff6b4fd5758a590ef03b5403b dotfiles/packages/i3blocks/scripts/network -rwxr-xr-x 927 bytes
7dd5e024 — Damien Tardy-Panis add mako package config 3 years ago
                                                                                
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
37
#! /usr/bin/env zsh

NETWORK_INFO=$(
  nmcli --fields type,state,connection device status \
    | tr --squeeze-repeats ' '
)

if echo "${NETWORK_INFO}" \
     | grep --quiet 'ethernet connected'; then
  IS_ETHERNET_CONNECTED=1
else
  IS_ETHERNET_CONNECTED=0
fi

if echo "${NETWORK_INFO}" \
     | grep --quiet 'wifi connected'; then
  IS_WIFI_CONNECTED=1
else
  IS_WIFI_CONNECTED=0
fi

WIFI_CONNECTION=$(
  echo "${NETWORK_INFO}" \
    | grep 'wifi connected' \
    | cut --delimiter ' ' --fields 3-
)

# NetworkManager automatically favors wired connections over wireless
if [[ "${IS_ETHERNET_CONNECTED}" -eq 1 ]]; then
  echo "<span foreground='#{color/base0A/hex}'></span> Wired"
elif [[ "${IS_WIFI_CONNECTED}" -eq 1 ]]; then
  echo "<span foreground='#{color/base0A/hex}'></span> ${WIFI_CONNECTION}"
else
  echo "<span foreground='#{color/base0A/hex}'></span> Disconnected"
  echo
  echo '#{color/warning/hex}'
fi