diff --git a/scripts/i3blocks/iface b/scripts/i3blocks/iface index 7014979..dae871c 100755 --- a/scripts/i3blocks/iface +++ b/scripts/i3blocks/iface @@ -1,6 +1,7 @@ #!/bin/bash # Copyright (C) 2014 Julien Bonjean # Copyright (C) 2014 Alexander Keller +# Copyright (C) 2019 Jesús E. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -18,10 +19,10 @@ #------------------------------------------------------------------------ # Use the provided interface, otherwise the device used for the default route. -if [[ -n $BLOCK_INSTANCE ]]; then - IF=$BLOCK_INSTANCE -else - IF=$(ip route | awk '/^default/ { print $5 ; exit }') +if [[ -z $IF ]] && [[ -n $BLOCK_INSTANCE ]]; then + IF=$BLOCK_INSTANCE +elif [[ -z $IF ]]; then + IF=$(ip route | awk '/^default/ { print $5 ; exit }') fi #------------------------------------------------------------------------ @@ -32,27 +33,27 @@ fi #------------------------------------------------------------------------ -if [[ "$(cat /sys/class/net/$IF/operstate)" = 'down' ]]; then - echo down # full text - echo down # short text - echo \#FF0000 # color - exit +if [[ "$(cat "/sys/class/net/$IF/operstate")" = 'down' ]]; then + echo down # full text + echo down # short text + echo \#FF0000 # color + exit fi case $1 in - -4) - AF=inet ;; - -6) - AF=inet6 ;; - *) - AF=inet6? ;; + -4) + AF=inet ;; + -6) + AF=inet6 ;; + *) + AF=inet6? ;; esac # if no interface is found, use the first device with a global scope -IPADDR=$(ip addr show $IF | perl -n -e "/$AF ([^\/]+).* scope global/ && print \$1 and exit") +IPADDR=$(ip addr show "$IF" | perl -n -e "/$AF ([^\/]+).* scope global/ && print \$1 and exit") case $BLOCK_BUTTON in - 3) echo -n "$IPADDR" | xclip -q -se c ;; + 3) echo -n "$IPADDR" | xclip -q -se c ;; esac #------------------------------------------------------------------------