1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 06:37:46 +00:00
nu_scripts/modules/network/sockets/sockets.nu
2024-10-29 06:31:52 -05:00

28 lines
1.1 KiB
Text

export def main [--abbreviate-java-class-paths (-j)] {
let input = (^lsof +c 0xFFFF -i -n -P)
let header = ($input | lines
| take 1
| each { str downcase | str replace ' name$' ' name state' })
let body = ($input | lines
| skip 1
| each { str replace '([^)])$' '$1 (NONE)' | str replace ' \((.+)\)$' ' $1' })
[$header] | append $body
| to text
| detect columns
| upsert 'pid' { |r| $r.pid | into int }
| rename --column { name: connection }
| reject 'command'
| join (ps -l) 'pid' 'pid'
| if $abbreviate_java_class_paths {
upsert 'classpath' { |r| $r.command | java-cmd classpath }
| upsert 'command' { |r| $r.command | java-cmd abbreviate-classpath }
} else { $in }
}
export def 'java-cmd classpath' [] {
str replace '.* -classpath +(.+\.jar) +.*' '$1' | split row ':'
}
export def 'java-cmd abbreviate-classpath' [] {
str replace '[^ ]*\.jar' '*.jar'
}