34 lines
959 B
Nu
34 lines
959 B
Nu
# Processes sorted by CPU, optionally filtered by name
|
|
def psk [query?: string] {
|
|
ps | sort-by cpu -r
|
|
| if $query != null { where name =~ $query } else { $in }
|
|
}
|
|
|
|
# Listening TCP ports with process info
|
|
def ports [] {
|
|
^ss -tlnp
|
|
| detect columns
|
|
| rename state recv-q send-q local peer process
|
|
| each {|r| $r | upsert port (try { $r.local | split row ":" | last | into int } catch { null })}
|
|
| select state local port process
|
|
| sort-by port
|
|
}
|
|
|
|
# Repeatedly clears and reruns a closure — nu-native watch replacement
|
|
def rewatch [interval: duration, cmd: closure] {
|
|
loop {
|
|
clear
|
|
let dim = $env.config.color_config.hints
|
|
print $"(ansi { fg: $dim })(date now | format date '%H:%M:%S')(ansi reset)"
|
|
do $cmd | print
|
|
sleep $interval
|
|
}
|
|
}
|
|
|
|
# Environment variables as a filterable sorted table
|
|
def envs [query?: string] {
|
|
$env | transpose key value
|
|
| if $query != null { where key =~ $query } else { $in }
|
|
| sort-by key
|
|
}
|