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

View File

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