From ec8e82745e4a7ee6076e115dc578a370d29914e2 Mon Sep 17 00:00:00 2001 From: appeasementPolitik <108810900+appeasementPolitik@users.noreply.github.com> Date: Wed, 16 Aug 2023 14:38:10 +0000 Subject: [PATCH] sb-internet: replace grep/sed commands for more efficiency (#1349) --- .local/bin/statusbar/sb-internet | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.local/bin/statusbar/sb-internet b/.local/bin/statusbar/sb-internet index 94b7da2..4c8131c 100755 --- a/.local/bin/statusbar/sb-internet +++ b/.local/bin/statusbar/sb-internet @@ -17,10 +17,17 @@ case $BLOCK_BUTTON in 6) "$TERMINAL" -e "$EDITOR" "$0" ;; esac -if grep -xq 'up' /sys/class/net/w*/operstate 2>/dev/null ; then +# Wifi +if [ "$(cat /sys/class/net/w*/operstate 2>/dev/null)" = 'up' ] ; then wifiicon="$(awk '/^\s*w/ { print "📶", int($3 * 100 / 70) "% " }' /proc/net/wireless)" -elif grep -xq 'down' /sys/class/net/w*/operstate 2>/dev/null ; then - grep -xq '0x1003' /sys/class/net/w*/flags && wifiicon="📡 " || wifiicon="❌ " +elif [ "$(cat /sys/class/net/w*/operstate 2>/dev/null)" = 'down' ] ; then + [ "$(cat /sys/class/net/w*/flags 2>/dev/null)" = '0x1003' ] && wifiicon="📡 " || wifiicon="❌ " fi -printf "%s%s%s\n" "$wifiicon" "$(sed "s/down/❎/;s/up/🌐/" /sys/class/net/e*/operstate 2>/dev/null)" "$(sed "s/.*/🔒/" /sys/class/net/tun*/operstate 2>/dev/null)" +# Ethernet +[ "$(cat /sys/class/net/e*/operstate 2>/dev/null)" = 'up' ] && ethericon="🌐 " || ethericon="❎ " + +# TUN +[ -n "$(cat /sys/class/net/tun*/operstate 2>/dev/null)" ] && tunicon="🔒 " + +printf "%s%s%s\n" "$wifiicon" "$ethericon" "$tunicon"