aboutsummaryrefslogtreecommitdiff
path: root/i3blocks
diff options
context:
space:
mode:
Diffstat (limited to 'i3blocks')
-rwxr-xr-xi3blocks/i3internet.sh73
1 files changed, 43 insertions, 30 deletions
diff --git a/i3blocks/i3internet.sh b/i3blocks/i3internet.sh
index 4065a31..3e63276 100755
--- a/i3blocks/i3internet.sh
+++ b/i3blocks/i3internet.sh
@@ -4,41 +4,54 @@
# Depends on nmcli and ip for IPs
case $BLOCK_BUTTON in
- 1) i3-msg "exec urxvt -title "floating" -e nmtui" >/dev/null ;;
+ 1) i3-msg "exec urxvt -title \"floating\" -e nmtui" >/dev/null ;;
esac
-wifiDev="wlp2s0"
-ethDev=""
-wstatus="$(cat /sys/class/net/$wifiDev/operstate)"
-estatus="$(cat /sys/class/net/$ethDev/operstate)"
-tick=✅
-wifiSymbol="📶"
-ethSymbol="🌐"
+wifiDev="$CONFIG_WIFI_DEV"
+ethDev="$CONFIG_ETH_DEV"
+tick="✅"
+wifiSymbol=""
+wifi=""
+ethSymbol=""
+eth=""
-if [ "$wstatus" = "down" ]; then
- wifi="❌"
-elif [ "$(nmcli | fgrep "$wifiDev: connecting ")" ]; then
- step="$(nmcli | fgrep "$wifiDev: connecting " | sed 's/^.*(/(/;s/).*$/)/')"
- wifi="$tick <span color='#fabd2f'>$(nmcli | fgrep "$wifiDev: " | cut -d' ' -f5-) $step</span>"
-else
- # with IP
- #wifi="$tick$(nmcli | fgrep "$wifiDev: connected to " | cut -d' ' -f4-) ($(ip addr show $wifiDev | fgrep "inet " | cut -d' ' -f6)) ($(egrep "^\s*w" /proc/net/wireless | awk '{print int($3 * 100 / 70)"%"}'))"
- # with name
- wifi="$tick <span color='#79ff79'>$(nmcli | fgrep "$wifiDev: connected to " | cut -d' ' -f4-) ($(egrep '^\s*w' /proc/net/wireless | awk '{print int($3 * 100 / 70)"%"}'))</span>"
+if [ -n "$wifiDev" ]; then
+ wifiSymbol="📶"
+ wstatus="$(cat "/sys/class/net/$wifiDev/operstate")"
+ if [ "$wstatus" = "down" ]; then
+ wifi="❌"
+ elif nmcli | grep -F -q "$wifiDev: connecting "; then
+ step="$(nmcli | grep -F "$wifiDev: connecting " | sed 's/^.*(/(/;s/).*$/)/')"
+ wifi="$tick <span color='#fabd2f'>$(nmcli | grep -F "$wifiDev: " |
+ cut -d' ' -f5-) $step</span>"
+ else
+ # with IP
+ #wifi="$tick$(nmcli | fgrep "$wifiDev: connected to " |
+ #cut -d' ' -f4-) ($(ip addr show $wifiDev | fgrep "inet " |
+ #cut -d' ' -f6)) ($(egrep "^\s*w" /proc/net/wireless |
+ #awk '{print int($3 * 100 / 70)"%"}'))"
+ # with name
+ wifi="$tick <span color='#79ff79'>$(nmcli |
+ grep -F "$wifiDev: connected to " |
+ cut -d' ' -f4-) ($(grep -E '^\s*w' /proc/net/wireless |
+ awk '{print int($3 * 100 / 70)"%"}'))</span>"
+ fi
fi
-[ -z "$ethDev" ] && echo "$wifiSymbol$wifi" && exit 0
-
-if [ -z "$(nmcli | fgrep "$ethDev")" ]; then
- en="❌❗ No $ethDev"
-elif [ "$estatus" = "down" ]; then
- en="❌"
-else
- # with IP
- #en=$(ip addr show $ethDev | fgrep "inet " | cut -d' ' -f6)
- # no IP
- en=$tick
+if [ -n "$ethDev" ]; then
+ ethSymbol="🌐"
+ estatus="$(cat "/sys/class/net/$ethDev/operstate")"
+ if ! nmcli | grep -F -q "$ethDev"; then
+ eth="❌❗ No $ethDev"
+ elif [ "$estatus" = "down" ]; then
+ eth="❌"
+ else
+ # with IP
+ #eth=$(ip addr show $ethDev | fgrep "inet " | cut -d' ' -f6)
+ # no IP
+ eth=$tick
+ fi
fi
-echo "$wifiSymbol$wifi $ethSymbol$en"
+echo "$wifiSymbol$wifi $ethSymbol$eth" | sed 's/^ *//' | sed 's/ *$//'
exit 0