From 4e54c2eba4d4858c84acefdfbd529d0cc0e2ed98 Mon Sep 17 00:00:00 2001 From: InigoGutierrez Date: Mon, 2 Dec 2019 22:52:09 +0100 Subject: Generalized internet i3blocks script. --- i3blocks/i3internet.sh | 73 +++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 30 deletions(-) (limited to 'i3blocks') 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 $(nmcli | fgrep "$wifiDev: " | cut -d' ' -f5-) $step" -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 $(nmcli | fgrep "$wifiDev: connected to " | cut -d' ' -f4-) ($(egrep '^\s*w' /proc/net/wireless | awk '{print int($3 * 100 / 70)"%"}'))" +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 $(nmcli | grep -F "$wifiDev: " | + cut -d' ' -f5-) $step" + 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 $(nmcli | + grep -F "$wifiDev: connected to " | + cut -d' ' -f4-) ($(grep -E '^\s*w' /proc/net/wireless | + awk '{print int($3 * 100 / 70)"%"}'))" + 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 -- cgit v1.2.1