Conversation
Fix ethernet icon for systems with multiple NICs wherein `cat /sys/class/net/e*/operstate ` outputs multiple lines. Icon now shows connected when one or more NICs are connected.
|
This does not work if 2 NICs are "up" and grep return both, and then both "up" gets compared to a single "up" and return false as if it was down. $ [ "$(echo -e "up\nup" | grep "up")" = 'up' ] && echo "🌐" || echo "❎"
❎This would be better instead: cat /sys/class/net/e*/operstate 2>/dev/null | grep -q "up" && ethericon="🌐" || ethericon="❎"If grep finds at least one instance of "up" it will return a "0" (no errors) return code and "🌐" will be put in the variable. You can try the following for proof: $ echo -e "up\nup" | grep -q "up" && echo "🌐" || echo "❎"
🌐
$ echo -e "up\ndown" | grep -q "up" && echo "🌐" || echo "❎"
🌐
$ echo "down" | grep -q "up" && echo "🌐" || echo "❎"
❎ |
|
Thanks for pointing that out. This is why I rarely open PRs. |
|
Small suggestion, you can change to: It's slightly faster because cat is not needed anymore, and the -m1 option makes grep instantly stop after it has found its first match. |
|
holy shit i was catting into grep xd |
Fix ethernet icon for systems with multiple NICs wherein
cat /sys/class/net/e*/operstateoutputs multiple lines. Icon now shows connected when one or more NICs are connected.