mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-02 07:07:46 +00:00
dp for docker ps
support docker and podman (#421)
* dp for `docker ps` support docker and podman * dp for `docker ps` support nerdctl --------- Co-authored-by: agent <agent@nuc>
This commit is contained in:
parent
1884426d79
commit
e7976c5cc1
1 changed files with 20 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
|||
export-env {
|
||||
for c in [podman nerdctl docker] {
|
||||
if not (whereis $c | parse -r '.+: (.+)' | is-empty) {
|
||||
if not (which $c | is-empty) {
|
||||
let-env docker-cli = $c
|
||||
break
|
||||
}
|
||||
|
@ -9,13 +9,28 @@ export-env {
|
|||
|
||||
export def dp [] {
|
||||
# ^$env.docker-cli ps --all --no-trunc --format='{{json .}}' | jq
|
||||
^$env.docker-cli ps -a --format '{"id":"{{.ID}}", "image": "{{.Image}}", "name":"{{.Names}}", "cmd":"{{.Command}}", "port":"{{.Ports}}", "status":"{{.Status}}", "created":"{{.Created}}"}'
|
||||
| lines
|
||||
| each {|x|
|
||||
let cli = $env.docker-cli
|
||||
if $cli == 'docker' {
|
||||
^$cli ps -a --format '{"id":"{{.ID}}", "image": "{{.Image}}", "name":"{{.Names}}", "cmd":{{.Command}}, "port":"{{.Ports}}", "status":"{{.Status}}", "created":"{{.CreatedAt}}"}'
|
||||
| lines
|
||||
| each {|x|
|
||||
let r = ($x | from json)
|
||||
let t = ($r.created | str substring ',25' | into datetime -f '%Y-%m-%d %H:%M:%S %z' ) - 8hr
|
||||
$r | upsert created $t
|
||||
}
|
||||
} else if $cli == 'podman' {
|
||||
^$cli ps -a --format '{"id":"{{.ID}}", "image": "{{.Image}}", "name":"{{.Names}}", "cmd":"{{.Command}}", "port":"{{.Ports}}", "status":"{{.Status}}", "created":"{{.Created}}"}'
|
||||
| lines
|
||||
| each {|x|
|
||||
let r = ($x | from json)
|
||||
let t = ($r.created | str substring ',32' | into datetime ) - 8hr
|
||||
$r | upsert created $t
|
||||
}
|
||||
}
|
||||
} else {
|
||||
^$cli ps -a
|
||||
| from ssv
|
||||
| rename id image cmd created status port name
|
||||
}
|
||||
}
|
||||
|
||||
export def di [] {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue