#!/bin/sh #should *probably* work with most bourne-like posix compatible shells, I think? #also using $(()) not sure if it's in posix spec, bash and dash should work tho #also using `column` and busybox alias sed="busybox sed" alias expand="busybox expand" case "$1" in ""|"-u"|"--utf") #top line char tl='━' #bottom line char bl='═' #$tl #left line char ll='│' #right line char rl=$ll #header line left hl='┃' #$ll #header line right hr=$hl #$rl #corner top-left ctl='┏' #corner top-right ctr='┓' #corner bottom-left cbl='╘' #corner bottom-right cbr='╛' #separator line horizontal char slh='─' #separator left end sle='┞─' #separator right end sre='─┦' ;; #---------------------- "-a"|"--ascii") #top line char tl='~' #bottom line char bl='=' #$tl #left line char ll='!' #right line char rl=$ll #header line left hl='|' #$ll #header line right hr=$hl #$rl #corner top-left ctl='/' #ctl='+' #corner top-right ctr='\\' #ctr='+' #corner bottom-left cbl=$ctr #corner bottom-right cbr=$ctl #separator line horizontal char slh='-' #separator left end sle='|-' #separator right end sre='-|' ;; "-r"|"--raw")true;; *) echo "syntax: $0 [-u|--utf|-a|--ascii|-r|--raw]" echo "defaults to unicode mode" echo "raw mode was an unintentional side effect" exit;; esac thing=$( ip a| grep -vE "^([ ]* inet(6|)?) ((\:\:1)|fe80\:\:|(127\.0\.0\.1))"| grep inet| tr -s " "| cut -d" " -f3| sed -e "s|/|\t/|" -e "1s/^/ADDRESSES MASK\n/"|expand -t 3); echo "$thing" len1=$( echo $thing| sed "s/\s/&\n/g"| sed "Ns/\n//"| cut -d" " -f1| wc -L); echo $len1 len2=$( echo $thing| sed "s/\s/&_\n/g"| sed "Ns/\n//"| cut -d" " -f2| wc -L); echo $len2 echo "$thing"| sed -e "2s/^/$(printf %${len1}s|sed "s/./$slh/g")$(printf %${len2}s|sed "s/./$slh/g")\n/"| sed -e "s/^/${ll} /" -e "s/$/\t ${rl}/" | sed -e "1s/^$ll /$hl /" -e "1s/ $rl$/ $hr/" \ -e "2s/^$ll /$sle/" -e "2s/ $rl$/$sre/" | tr -d \\t| #column -t -s" " -o ""| sed "1s\`^\`${ctl}${tl}${tl}$(printf "%${len1:-"1"}s"|sed "s/./$tl/g")$(printf "%${len2:-"1"}s"|sed "s/./$tl/g")${ctr}\n\`"|sed "$ s\`$\`\n${cbl}${bl}${bl}$(printf "%${len1:-"1"}s"| sed "s/./$bl/g")$(printf "%${len2:-"1"}s"| sed "s/./$bl/g")${cbr}\`"