diff --git a/.config/polybar/amidown.sh b/.config/polybar/amidown.sh new file mode 100755 index 00000000..1ed8fd14 --- /dev/null +++ b/.config/polybar/amidown.sh @@ -0,0 +1,60 @@ +#! /bin/bash +# +# netstatus.sh +# Copyright (C) 2018 rehashedsalt +# +# Distributed under terms of the MIT license. +# + +# Global vars +if_default="" +ipv4_private="" + +# Define our tests +function test-gateway { + if ip r | grep default > /dev/null 2>&1; then + ipr="$(ip r | grep default)" + ipv4_private="$(echo $ipr | awk '{print $3}')" + if_default="$(echo $ipr | awk '{print $5}')" + unset ipr + return 0 + else + return 1 + fi +} + +function test-internet { + if ping -c 1 8.8.8.8 > /dev/null 2>&1; then + return 0 + else + return 1 + fi +} + +function test-dns { + if ping -c 1 google.com > /dev/null 2>&1; then + return 0 + else + return 1 + fi +} + +# Actually go through with them +if ! test-gateway; then + printf "NONE" + exit 1 +fi + +if ! test-internet; then + printf "LOCAL" + exit 2 +fi + +if ! test-dns; then + printf "NO DNS" + exit 3 +fi + +printf "UP" +exit 0 + diff --git a/.config/polybar/config b/.config/polybar/config index ca694bac..a93f5d3c 100644 --- a/.config/polybar/config +++ b/.config/polybar/config @@ -88,7 +88,7 @@ border-top-size = 0 modules-left = ${env:PB_BAR_PRIMARY_MODULES_LEFT:battery cpu memory} modules-center = ${env:PB_BAR_PRIMARY_MODULES_CENTER: bspwm} -modules-right = ${env:PB_BAR_PRIMARY_MODULES_RIGHT:xbacklight volume date} +modules-right = ${env:PB_BAR_PRIMARY_MODULES_RIGHT:amidown xbacklight volume date} [bar/primary-2] monitor = ${env:PB_MONITOR:eDP-1} @@ -144,6 +144,14 @@ content = " " # OTHER #==================== +[module/amidown] +type = custom/script +format-prefix = "NET: " +format-prefix-foreground = ${res/colors.alert} +exec = ~/.config/polybar/amidown.sh +exec-if = ! ping -c 1 google.com +interval = 15 + [module/battery] type = internal/battery format-charging =