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 | |
parent | a2d8e3bf021c7a060034949d1c06b99b01e4d117 (diff) | |
download | i3-config-b200c2cf3fe4aa13f8e07eb69016206ae56127ae.tar.lz i3-config-b200c2cf3fe4aa13f8e07eb69016206ae56127ae.tar.xz i3-config-b200c2cf3fe4aa13f8e07eb69016206ae56127ae.zip |
[iface] refactoring
-rw-r--r-- | i3blocks.conf | 6 | ||||
-rwxr-xr-x | scripts/i3blocks/iface | 47 |
2 files changed, 31 insertions, 22 deletions
diff --git a/i3blocks.conf b/i3blocks.conf index ab9792a..b0dd24b 100644 --- a/i3blocks.conf +++ b/i3blocks.conf @@ -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 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 |