mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 22:57:46 +00: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
2 changed files with 33 additions and 11 deletions
|
@ -63,9 +63,10 @@ export def container-list [
|
||||||
{
|
{
|
||||||
name: $r.Name?
|
name: $r.Name?
|
||||||
hostname: $r.Config.Hostname?
|
hostname: $r.Config.Hostname?
|
||||||
|
id: $r.Id
|
||||||
|
status: $r.State.Status?
|
||||||
image: $image
|
image: $image
|
||||||
created: $r.Created
|
created: $r.Created
|
||||||
id: $r.Id
|
|
||||||
ports: $p
|
ports: $p
|
||||||
env: $imgEnv
|
env: $imgEnv
|
||||||
mounts: $m
|
mounts: $m
|
||||||
|
@ -114,6 +115,7 @@ export def image-list [
|
||||||
os: $r.Os
|
os: $r.Os
|
||||||
size: $r.Size
|
size: $r.Size
|
||||||
labels: $r.Labels?
|
labels: $r.Labels?
|
||||||
|
user: $r.Config.User?
|
||||||
env: $e
|
env: $e
|
||||||
entrypoint: $r.Config.Entrypoint?
|
entrypoint: $r.Config.Entrypoint?
|
||||||
cmd: $r.Config.Cmd?
|
cmd: $r.Config.Cmd?
|
||||||
|
@ -128,15 +130,35 @@ def "nu-complete docker ps" [] {
|
||||||
}
|
}
|
||||||
|
|
||||||
def "nu-complete docker containers" [] {
|
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
|
^$env.docker-cli ps -a
|
||||||
| from ssv -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" [] {
|
def "nu-complete docker images" [] {
|
||||||
|
@ -211,7 +233,7 @@ export def container-copy-file [
|
||||||
}
|
}
|
||||||
|
|
||||||
# remove container
|
# 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
|
^$env.docker-cli ...($n | with-flag -n) container rm -f $ctn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ def agree [
|
||||||
} else {
|
} else {
|
||||||
$'($prompt)'
|
$'($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 ] {
|
def tips [ msg ] {
|
||||||
|
@ -117,7 +117,7 @@ export def gb [
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ($branch | is-empty) {
|
} else if ($branch | is-empty) {
|
||||||
let merged = git branch --merged
|
let merged = git branch --merged
|
||||||
| lines
|
| lines
|
||||||
| each { $in | parse -r '\s*\*?\s*(?P<b>[^\s]+)' | get 0.b }
|
| each { $in | parse -r '\s*\*?\s*(?P<b>[^\s]+)' | get 0.b }
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue