i3_cockpit/i3block_shell/ip.sh

26 lines
521 B
Bash
Executable File

#!/bin/bash
# status bar ip lookup
# when offline
if [[ $(ip a | grep "state" | grep -Ev 'tun|lo' | grep "DOWN ") ]]; then
printmain="down"
printsmall="down"
printcolor="#FF0000"
fi
# when connected
if [[ $(ip a | grep "state" | grep -Ev 'tun|lo' | grep "UP ") ]]; then
printmain=$(ip -br addr show | grep -v 'lo' \
| awk '{print $3}' | awk -F '/' {'print $1}' | head -n 1)
printsmall=""
printcolor="#00FF00"
fi
# echo
echo "$printmain"
echo "$printsmall"
echo "$printcolor"
##
exit 0