aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorInigoGutierrez <inigogf.95@gmail.com>2019-12-02 22:52:09 +0100
committerInigoGutierrez <inigogf.95@gmail.com>2019-12-02 22:52:09 +0100
commit4e54c2eba4d4858c84acefdfbd529d0cc0e2ed98 (patch)
tree201bb7e24e23665a75d0fbaa83f38084b28e4ea5
parentb2e32ae0be916d4283b79df4c5163e2a25513f69 (diff)
downloadscripts-4e54c2eba4d4858c84acefdfbd529d0cc0e2ed98.tar.gz
scripts-4e54c2eba4d4858c84acefdfbd529d0cc0e2ed98.zip
Generalized internet i3blocks script.
-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