diff options
author | Jesús <heckyel@hyperbola.info> | 2019-07-14 18:04:07 -0500 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2019-07-14 18:04:07 -0500 |
commit | 557015eaa0607d34907378a0122e9c2c4d70ce6f (patch) | |
tree | 0a34f8b378079c11862c299171abff04ffe2c917 | |
parent | 1c9a6121ab0c014284545228e671ca64c5a8b8f5 (diff) | |
download | i3-config-557015eaa0607d34907378a0122e9c2c4d70ce6f.tar.lz i3-config-557015eaa0607d34907378a0122e9c2c4d70ce6f.tar.xz i3-config-557015eaa0607d34907378a0122e9c2c4d70ce6f.zip |
improve and fix issues shellcheck
-rwxr-xr-x | scripts/i3blocks/iface | 35 |
1 files changed, 18 insertions, 17 deletions
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 <julien@bonjean.info> # Copyright (C) 2014 Alexander Keller <github@nycroth.com> +# Copyright (C) 2019 Jesús E. <heckyel@hyperbola.info> # 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 #------------------------------------------------------------------------ |