From cce8cf0917b58ea98ea2e53825d5f7821f3143b8 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Sun, 2 Oct 2022 18:56:08 -0400 Subject: [PATCH] Use jq for formatting ip addresses in netstatus.sh --- .config/xfce4/panel/scripts/netstatus.sh | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/.config/xfce4/panel/scripts/netstatus.sh b/.config/xfce4/panel/scripts/netstatus.sh index e6eccb6..8ef7cd0 100755 --- a/.config/xfce4/panel/scripts/netstatus.sh +++ b/.config/xfce4/panel/scripts/netstatus.sh @@ -8,15 +8,12 @@ function doPing () { sed 's/.*time=\([0-9\.]*\).*/'"$2"':\1ms/' } -if [[ "$@" -ne "" ]] -then - interfaces=$(ip -4 -o a | grep "$@") -else - interfaces=$(ip -4 -o a) -fi -ip=$(echo "$interfaces" | \ - sed 's/^[0-9]*: \([^ ]*\) inet \([0-9.]*\).*/\1:\2/g' | \ - grep -v lo | \ - tr '\n' ' ') +function get_ip_addresses() { + ip -4 -json address | jq -r ' +map(select(.ifname != "lo") | + .ifname + ":" + (.addr_info | map(.local) | join(","))) | + join(" ") +' +} -echo -n "${ip}$(doPing 8.8.8.8 G)" +echo -n "$(get_ip_addresses) $(doPing 8.8.8.8 G)"