From fba38f5317a9992874a9baf6bf8b9bda3597b84c Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Tue, 15 Sep 2020 21:28:05 -0400 Subject: Add a sockstat shell function for OpenBSD. Also adjust showsshhosts --- mkshrc | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'mkshrc') diff --git a/mkshrc b/mkshrc index f39778e..3e64d51 100644 --- a/mkshrc +++ b/mkshrc @@ -27,7 +27,9 @@ setaliases() { alias search='grep -niRIE' alias rot13="tr 'A-Za-z' 'N-ZA-Mn-za-m'" alias setxkbmap-list="man xkeyboard-config" - alias showsshhosts="cat ~/.ssh/config ~/.ssh/inc/* | awk '/^[hH]ost /{print \$2}'" + showsshhosts() { + cat ~/.ssh/config ~/.ssh/inc/* | awk '/^[hH]ost /{$1=""; print $0}' + } # docker-getip $container_id alias docker-getip="docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'" alias xa='xargs -I{}' @@ -44,6 +46,36 @@ setaliases() { set +x } + if [ "$(uname)" = "OpenBSD" ] ; then + sockstat() { + fstat | awk ' + BEGIN { + OFS="\t"; + } + { + if ( NR == 1 ) { + print($1, $2, $3, $5, $7, "ADDR"); + } + if( $0 ~ /tcp|udp/ ) { + if(!($0 ~ /[<-]-[->]/)) { + l = $1 "\t" $2 "\t" $3 "\t" $5 "\t" $7 "\t"; + if($7 == "tcp") { + services[$3] = l $9; + } else if ($7 == "udp") { + services[$3] = l $8; + } + } + } + } + END { + for(service in services) { + print(services[service]); + } + } + ' | column -t + } + fi + if [ "$(uname)" = "Linux" ] ; then # Sets capslock to be another control key, only works with PS2 keyboards alias unfuck_capslock='setkeycodes 3a 29' -- cgit v1.2.3