mirror of
https://github.com/nushell/nu_scripts.git
synced 2024-10-26 13:55:28 +03:00
nu-complete docker containers: show all containers (#778)
- use `!` tag failed containers - if there are duplicate names, the id comes first. --------- Co-authored-by: nash <nash@iffy.me>
This commit is contained in:
parent
8a2dcf6cf8
commit
6d98fee3ba
@ -63,9 +63,10 @@ export def container-list [
|
||||
{
|
||||
name: $r.Name?
|
||||
hostname: $r.Config.Hostname?
|
||||
id: $r.Id
|
||||
status: $r.State.Status?
|
||||
image: $image
|
||||
created: $r.Created
|
||||
id: $r.Id
|
||||
ports: $p
|
||||
env: $imgEnv
|
||||
mounts: $m
|
||||
@ -114,6 +115,7 @@ export def image-list [
|
||||
os: $r.Os
|
||||
size: $r.Size
|
||||
labels: $r.Labels?
|
||||
user: $r.Config.User?
|
||||
env: $e
|
||||
entrypoint: $r.Config.Entrypoint?
|
||||
cmd: $r.Config.Cmd?
|
||||
@ -128,15 +130,35 @@ def "nu-complete docker ps" [] {
|
||||
}
|
||||
|
||||
def "nu-complete docker containers" [] {
|
||||
^$env.docker-cli ps
|
||||
| from ssv -a
|
||||
| each {|x| {description: $x.'CONTAINER ID' value: $x.NAMES}}
|
||||
}
|
||||
|
||||
def "nu-complete docker all containers" [] {
|
||||
^$env.docker-cli ps -a
|
||||
| from ssv -a
|
||||
| each {|x| {description: $x.'CONTAINER ID' value: $x.NAMES}}
|
||||
| each {|i|
|
||||
let st = if ($i.STATUS | str starts-with 'Up') { ' ' } else { '!' }
|
||||
{ id: $i.'CONTAINER ID', name: $i.NAMES, status: $st }
|
||||
}
|
||||
| group-by name
|
||||
| transpose k v
|
||||
| each {|i|
|
||||
let s = ($i.v | length) == 1
|
||||
$i.v | each {|i|
|
||||
if $s {
|
||||
{value: $i.name, description: $"($i.status) ($i.id)"}
|
||||
} else {
|
||||
{value: $i.id, description: $"($i.status) ($i.name)"}
|
||||
}
|
||||
}
|
||||
}
|
||||
| flatten
|
||||
}
|
||||
|
||||
# TODO: filter by description
|
||||
def "nu-complete docker containers b" [] {
|
||||
^$env.docker-cli ps -a
|
||||
| from ssv -a
|
||||
| each {|i|
|
||||
let s = if ($i.STATUS | str starts-with 'Up') { ' ' } else { '!' }
|
||||
{ value: $i.'CONTAINER ID', description: $"($s) ($i.NAMES)" }
|
||||
}
|
||||
}
|
||||
|
||||
def "nu-complete docker images" [] {
|
||||
@ -211,7 +233,7 @@ export def container-copy-file [
|
||||
}
|
||||
|
||||
# remove container
|
||||
export def container-remove [ctn: string@"nu-complete docker all containers" -n: string@"nu-complete docker ns"] {
|
||||
export def container-remove [ctn: string@"nu-complete docker containers" -n: string@"nu-complete docker ns"] {
|
||||
^$env.docker-cli ...($n | with-flag -n) container rm -f $ctn
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ def agree [
|
||||
} else {
|
||||
$'($prompt)'
|
||||
}
|
||||
( if $default_not { [no yes] } else { [yes no] } | input list $prompt) in [yes]
|
||||
(if $default_not { [no yes] } else { [yes no] } | input list $prompt) == 'yes'
|
||||
}
|
||||
|
||||
def tips [ msg ] {
|
||||
|
Loading…
Reference in New Issue
Block a user