[iface] refactoring

This commit is contained in:
Jesús 2019-10-01 13:02:30 -05:00
parent a2d8e3bf02
commit b200c2cf3f
No known key found for this signature in database
GPG Key ID: F6EE7BC59A315766
2 changed files with 31 additions and 22 deletions

View File

@ -87,8 +87,8 @@ interval=30
# instance=eth0
# instance=wlp2s0
color=#00FF00
# interval=10
interval=once
interval=10
# interval=once
separator=false
# [wifi]
@ -145,7 +145,7 @@ interval=10
# Require acpi → pacman -S acpi
# [battery]
# label=BAT
# #label=⚡
# # label=⚡
# #instance=1
# interval=30

View File

@ -19,11 +19,11 @@
#------------------------------------------------------------------------
# Use the provided interface, otherwise the device used for the default route.
if [[ -z $IF ]] && [[ -n $BLOCK_INSTANCE ]]; then
IF=$BLOCK_INSTANCE
elif [[ -z $IF ]]; then
IF=$(ip route | awk '/^default/ { print $5 ; exit }')
fi
IF="${IFACE:-$BLOCK_INSTANCE}"
IF="${IF:-$(ip route | awk '/^default/ { print $5 ; exit }')}"
# Exit if there is no default route
[[ -z "$IF" ]] && exit
#------------------------------------------------------------------------
@ -33,21 +33,30 @@ fi
#------------------------------------------------------------------------
if [[ "$(cat "/sys/class/net/$IF/operstate")" = 'down' ]]; then
echo down # full text
echo down # short text
echo \#FF0000 # color
exit
fi
AF=${ADDRESS_FAMILY:-inet6?}
LABEL="${LABEL:-}"
case $1 in
for flag in "$1" "$2"; do
case "$flag" in
-4)
AF=inet ;;
-6)
AF=inet6 ;;
*)
AF=inet6? ;;
esac
-L)
if [[ "$IF" = "" ]]; then
LABEL="iface "
else
LABEL="$IF: "
fi ;;
esac
done
if [[ "$IF" = "" ]] || [[ "$(cat "/sys/class/net/$IF/operstate")" = 'down' ]]; then
echo "${LABEL}down" # full text
echo "${LABEL}down" # short text
echo \#FF0000 # color
exit
fi
# look for the vpn connection, if no interface is found, use the first device with a global scope
if [[ $(ip addr show tun0) ]]; then
@ -62,5 +71,5 @@ esac
#------------------------------------------------------------------------
echo "$IPADDR" # full text
echo "$IPADDR" # short text
echo "$LABEL$IPADDR" # full text
echo "$LABEL$IPADDR" # short text