From c4be0fe3c58fe07e235f624974b4f8102a17ecca Mon Sep 17 00:00:00 2001 From: 0scar Date: Wed, 21 Oct 2020 17:51:56 +0200 Subject: Add some neat scripts --- .scripts/netinfo | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 .scripts/netinfo (limited to '.scripts/netinfo') diff --git a/.scripts/netinfo b/.scripts/netinfo new file mode 100755 index 0000000..92dd78c --- /dev/null +++ b/.scripts/netinfo @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +netstatus="$(awk '{ + n = split(FILENAME, a, "/") + printf("%-15s %s\n", a[n-1], $1) + }' /sys/class/net/[ew]*/operstate | sort -k 2)" + +function add_connected_address() { + TMPIFS=$IFS + IFS=' +' + for line in $netstatus; do + device=$(echo $line | awk '{print $1}') + address=$(ip addr show $device | sed -En 's/inet ([0-9\.]+).*/\1/p') + # Append Wifi AP if connected + [ -n "$address" ] && address=$address" ("$(iwgetid -r)")" + echo $line $address + done + IFS=$TMPIFS +} + +case $BLOCK_BUTTON in + 3) notify-send "Internet connection" "$(add_connected_address)" ;; +esac + +#echo "$(echo -e "$netstatus" | sed -En '/up$/p')" +#echo ====== + +if [ -z "$(echo -e "${netstatus}" | sed -En '/up$/p' | tr -d '\n')" ]; then + echo -n '' +else + echo -n "${netstatus}" | sed -En 's/^(w[^ ]+).*up//p;s/^(e[^ ]+).*up//p' +fi + -- cgit v1.3