Add community scripts for i3blocks

This commit is contained in:
2020-02-19 15:55:35 +00:00
parent 3233439d88
commit 3236629420
19 changed files with 746 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
#!/usr/bin/env bash
################################
# Shows IP address of a given interface
#
# @param {String} interface: The network interface to check
# @return {String(IP)}: IP address of the interface
################################
dir=$(dirname $0)
source "$dir/util.sh"
full=""
short=""
status=0
interface=${BLOCK_INSTANCE:-eth0}
netPath=/sys/class/net
interfacePath=$(echo $netPath/$interface)
# Expand wildcard interfaces
interface=${interfacePath#$netPath/}
state=$(cat $interfacePath/operstate)
if [ $state == "up" ]; then
ips=$(ip addr show $interface | perl -n -e'/inet (.+)\// && print $1')
ip=${ips:-0.0.0.0}
full=$ip
short=$full
fi
echo "$full"
echo "$short"
exit $status