diff options
author | Jesús <heckyel@hyperbola.info> | 2019-10-01 13:02:30 -0500 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2019-10-01 13:02:30 -0500 |
commit | b200c2cf3fe4aa13f8e07eb69016206ae56127ae (patch) | |
tree | 036eb9398efca47910d6179658ed1369932f380a /scripts | |
parent | a2d8e3bf021c7a060034949d1c06b99b01e4d117 (diff) | |
download | i3-config-b200c2cf3fe4aa13f8e07eb69016206ae56127ae.tar.lz i3-config-b200c2cf3fe4aa13f8e07eb69016206ae56127ae.tar.xz i3-config-b200c2cf3fe4aa13f8e07eb69016206ae56127ae.zip |
[iface] refactoring
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/i3blocks/iface | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/scripts/i3blocks/iface b/scripts/i3blocks/iface index af36bfe..da0145a 100755 --- a/scripts/i3blocks/iface +++ b/scripts/i3blocks/iface @@ -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,22 +33,31 @@ fi #------------------------------------------------------------------------ -if [[ "$(cat "/sys/class/net/$IF/operstate")" = 'down' ]]; then - echo down # full text - echo down # short text +AF=${ADDRESS_FAMILY:-inet6?} +LABEL="${LABEL:-}" + +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 exit 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 if [[ $(ip addr show tun0) ]]; then IPADDR=$(ip addr show tun0 | awk '/inet.*brd/ {print $2}' | awk -F'/' '{print $1}') @@ -62,5 +71,5 @@ esac #------------------------------------------------------------------------ -echo "$IPADDR" # full text -echo "$IPADDR" # short text +echo "$LABEL$IPADDR" # full text +echo "$LABEL$IPADDR" # short text |