2020-03-12 21:36:39 +04:00
|
|
|
#!/bin/bash
|
|
|
|
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
|
|
|
# frontend pour 'ip addr' qui formatte l'affichage pour prendre moins de place
|
|
|
|
|
2020-03-13 10:46:54 +04:00
|
|
|
if [ -x /usr/bin/ip ]; then IP=/usr/bin/ip
|
|
|
|
elif [ -x /bin/ip ]; then IP=/bin/ip
|
|
|
|
else IP=ip
|
|
|
|
fi
|
|
|
|
|
2020-03-12 21:36:39 +04:00
|
|
|
tty -s <&1 && isatty=1 || isatty=
|
|
|
|
|
2020-03-13 10:46:54 +04:00
|
|
|
"$IP" addr "$@" | awk -v isatty="$isatty" '
|
2020-03-12 21:36:39 +04:00
|
|
|
isatty && $0 ~ /^[0-9]/ {
|
|
|
|
$0 = gensub(/: ([^:]+):/, ": \x1B[32m\\1\x1B[0m:", 1)
|
|
|
|
}
|
|
|
|
isatty && $1 == "inet" {
|
|
|
|
$0 = gensub(/inet ([^ ]+) /, "inet \x1B[34m\\1\x1B[0m ", 1)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
if ($1 == "inet" || $1 == "inet6") {
|
|
|
|
printf "%s -- ", $0
|
|
|
|
getline
|
|
|
|
sub(/^ +/, "")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{ print }'
|