1
- export def has [name ] {
2
- $name in ($in | columns ) and (not ($in | get $name | is-empty ))
1
+ export-env {
2
+ for c in [podman nerdctl docker ] {
3
+ if not (whereis $c | parse - r ' .+: (.+)' | is-empty ) {
4
+ let-env docker-cli = $c
5
+ break
6
+ }
7
+ }
3
8
}
4
9
5
-
6
- alias docker = podman
7
-
8
10
export def dp [] {
9
- # docker ps --all --no-trunc --format='{{json .}}' | jq
10
- docker ps - a -- format ' {"id":"{{.ID}}", "image": "{{.Image}}", "name":"{{.Names}}", "cmd":"{{.Command}}", "port":"{{.Ports}}", "status":"{{.Status}}", "created":"{{.Created}}"}'
11
+ # ^$env. docker-cli ps --all --no-trunc --format='{{json .}}' | jq
12
+ ^$env. docker-cli ps - a -- format ' {"id":"{{.ID}}", "image": "{{.Image}}", "name":"{{.Names}}", "cmd":"{{.Command}}", "port":"{{.Ports}}", "status":"{{.Status}}", "created":"{{.Created}}"}'
11
13
| lines
12
14
| each {|x |
13
15
let r = ($x | from json )
@@ -17,63 +19,76 @@ export def dp [] {
17
19
}
18
20
19
21
export def di [] {
20
- docker images
22
+ ^$env. docker-cli images
21
23
| from ssv - a
22
24
| rename repo tag id created size
23
- | upsert size { |i | $i.size | into filesize }
25
+ | each {|x |
26
+ let size = ($x.size | into filesize )
27
+ let path = ($x.repo | split row ' /' )
28
+ let image = ($path | last )
29
+ let repo = ($path | range .. (($path | length ) - 2 ) | str join ' /' )
30
+ {
31
+ repo : $repo
32
+ image : $image
33
+ tag : $x.tag
34
+ id : $x.id
35
+ created : $x.created
36
+ size : $size
37
+ }
38
+ }
24
39
}
25
40
26
41
def "nu-complete docker ps" [] {
27
- docker ps
42
+ ^$env. docker-cli ps
28
43
| from ssv - a
29
44
| each {|x | {description : $x.NAMES value : $x . ' CONTAINER ID' }}
30
45
}
31
46
32
47
def "nu-complete docker container" [] {
33
- docker ps
48
+ ^$env. docker-cli ps
34
49
| from ssv - a
35
50
| each {|x | {description : $x . ' CONTAINER ID' value : $x.NAMES }}
36
51
}
37
52
38
53
def "nu-complete docker all container" [] {
39
- docker ps - a
54
+ ^$env. docker-cli ps - a
40
55
| from ssv - a
41
56
| each {|x | {description : $x . ' CONTAINER ID' value : $x.NAMES }}
42
57
}
43
58
44
59
def "nu-complete docker images" [] {
45
- docker images
60
+ ^$env. docker-cli images
46
61
| from ssv
47
62
| each {|x | $" ($x.REPOSITORY ):($x.TAG )" }
48
63
}
49
64
50
65
export def dl [ctn : string @" nu-complete docker container" - n : int = 100 ] {
51
66
let n = if $n == 0 { [] } else { [--tail $n ] }
52
- docker logs - f $n $ctn
67
+ ^$env. docker-cli logs - f $n $ctn
53
68
}
54
69
55
70
export def da [
56
71
ctn : string @" nu-complete docker container"
57
72
... args
58
73
] {
59
74
if ($args | is-empty ) {
60
- docker exec - it $ctn /bin/sh - c " [ -e /bin/zsh ] && /bin/zsh || [ -e /bin/bash ] && /bin/bash || /bin/sh"
75
+ ^$env. docker-cli exec - it $ctn /bin/sh - c " [ -e /bin/zsh ] && /bin/zsh || [ -e /bin/bash ] && /bin/bash || /bin/sh"
61
76
} else {
62
- docker exec - it $ctn $args
77
+ ^$env. docker-cli exec - it $ctn $args
63
78
}
64
79
}
65
80
66
81
def "nu-complete docker cp" [cmd : string , offset : int ] {
67
82
let argv = ($cmd | str substring [0 $offset ] | split row ' ' )
68
83
let p = if ($argv | length ) > 2 { $argv | get 2 } else { $argv | get 1 }
69
84
let ctn = (
70
- docker ps
85
+ ^$env. docker-cli ps
71
86
| from ssv - a
72
87
| each {|x | {description : $x . ' CONTAINER ID' value : $" ($x.NAMES ):" }}
73
88
)
74
89
let n = ($p | split row ' :' )
75
90
if $" ($n | get 0 ):" in ($ctn | get value ) {
76
- docker exec ($n | get 0 ) sh - c $" ls -dp ($n | get 1 )*"
91
+ ^$env. docker-cli exec ($n | get 0 ) sh - c $" ls -dp ($n | get 1 )*"
77
92
| lines
78
93
| each {|x | $" ($n | get 0 ):($x )" }
79
94
} else {
@@ -89,66 +104,66 @@ export def dcp [
89
104
lhs : string @" nu-complete docker cp" ,
90
105
rhs : string @" nu-complete docker cp"
91
106
] {
92
- docker cp $lhs $rhs
107
+ ^$env. docker-cli cp $lhs $rhs
93
108
}
94
109
95
110
export def dcr [ctn : string @" nu-complete docker all container" ] {
96
- docker container rm - f $ctn
111
+ ^$env. docker-cli container rm - f $ctn
97
112
}
98
113
99
114
export def dis [img : string @" nu-complete docker images" ] {
100
- docker inspect $img
115
+ ^$env. docker-cli inspect $img
101
116
}
102
117
103
118
export def dh [img : string @" nu-complete docker images" ] {
104
- docker history -- no-trunc $img | from ssv - a
119
+ ^$env. docker-cli history -- no-trunc $img | from ssv - a
105
120
}
106
121
107
122
export def dsv [... img : string @" nu-complete docker images" ] {
108
- docker save $img
123
+ ^$env. docker-cli save $img
109
124
}
110
125
111
126
export alias dld = podman load
112
127
113
128
export def dsp [] {
114
- docker system prune - f
129
+ ^$env. docker-cli system prune - f
115
130
}
116
131
117
132
export alias dspall = podman system prune -- all -- force -- volumes
118
133
119
134
export def drmi [img : string @" nu-complete docker images" ] {
120
- docker rmi $img
135
+ ^$env. docker-cli rmi $img
121
136
}
122
137
123
138
export def dt [from : string @" nu-complete docker images" to : string ] {
124
- docker tag $from $to
139
+ ^$env. docker-cli tag $from $to
125
140
}
126
141
127
142
export def dps [img : string @" nu-complete docker images" ] {
128
- docker push $img
143
+ ^$env. docker-cli push $img
129
144
}
130
145
131
146
export alias dpl = podman pull
132
147
133
148
### volume
134
149
export def dvl [] {
135
- docker volume ls | from ssv - a
150
+ ^$env. docker-cli volume ls | from ssv - a
136
151
}
137
152
138
153
def "nu-complete docker volume" [] {
139
154
dvl | get name
140
155
}
141
156
142
157
export def dvc [name : string ] {
143
- docker volume create
158
+ ^$env. docker-cli volume create
144
159
}
145
160
146
161
export def dvi [name : string @" nu-complete docker volume" ] {
147
- docker volume inspect $name
162
+ ^$env. docker-cli volume inspect $name
148
163
}
149
164
150
165
export def dvr [... name : string @" nu-complete docker volume" ] {
151
- docker volume rm $name
166
+ ^$env. docker-cli volume rm $name
152
167
}
153
168
154
169
### run
@@ -211,7 +226,7 @@ export def dr [
211
226
let netadmin = if $netadmin { [--cap-add=NET_ADMIN --device /dev/net/tun ] } else { [] }
212
227
let clip = if $with_x { [-e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix ] } else { [] }
213
228
let ssh = if ($ssh | is-empty ) { [] } else {
214
- let sshkey = (cat ([~/ .ssh $ssh ] | path join ) | split row ' ' | get 1 )
229
+ let sshkey = (cat ([$env .HOME .ssh $ssh ] | path join ) | split row ' ' | get 1 )
215
230
[-e $" ed25519_($sshuser )=($sshkey )" ]
216
231
}
217
232
let proxy = if ($proxy | is-empty ) { [] } else {
@@ -227,7 +242,7 @@ export def dr [
227
242
if $dry_run {
228
243
echo $" docker run --name ($name ) ($args | str join ' ' ) ($img ) ($cmd | flatten )"
229
244
} else {
230
- docker run -- name $name $args $img ($cmd | flatten )
245
+ ^$env. docker-cli run -- name $name $args $img ($cmd | flatten )
231
246
}
232
247
}
233
248
@@ -247,23 +262,25 @@ export def dx [
247
262
... cmd # command args
248
263
] {
249
264
let __dx_cache = {
250
- hs : ' stack:/opt/stack'
251
- rs : ' cargo:/opt/cargo'
252
- go : ' gopkg:/opt/gopkg '
253
- ng : ' ng:/srv'
254
- pg : ' pg:/var/lib/postgresql/data'
255
- }
265
+ hs : ' stack:/opt/stack'
266
+ rs : ' cargo:/opt/cargo'
267
+ go : ' gopkg:/opt/go/pkg '
268
+ ng : ' ng:/srv'
269
+ pg : ' pg:/var/lib/postgresql/data'
270
+ }
256
271
let c = do - i {$__dx_cache | transpose k v | where {|x | $dx | str contains $x.k } | get v.0 }
257
- let c = if ($c | is-empty ) { ' ' } else if $mount_cache {
258
- let c = ( $c
259
- | split row ' :'
260
- | each - n {|x | if $x.index == 1 { $" /cache($x.item )" } else { $x.item } }
261
- | str join ' :'
262
- )
263
- $" ($env .HOME )/.cache/($c )"
264
- } else {
265
- $" ($env .HOME )/.cache/($c )"
266
- }
272
+ let c = if ($c | is-empty ) {
273
+ ' '
274
+ } else if $mount_cache {
275
+ let c = ( $c
276
+ | split row ' :'
277
+ | each {|x i | if $i == 1 { $" /cache($x )" } else { $x } }
278
+ | str join ' :'
279
+ )
280
+ $" ($env .HOME )/.cache/($c )"
281
+ } else {
282
+ $" ($env .HOME )/.cache/($c )"
283
+ }
267
284
let proxy = if ($proxy | is-empty ) { [] } else { [--proxy $proxy ] }
268
285
if $dry_run {
269
286
print $" cache: ($c )"
@@ -281,16 +298,16 @@ def "nu-complete registry list" [cmd: string, offset: int] {
281
298
let tag = do - i { $cmd | get 4 }
282
299
if ($reg | is-empty ) {
283
300
if ($env | has ' REGISTRY_TOKEN' ) {
284
- fetch - H [authorization $" Basic ($env .REGISTRY_TOKEN )" ] $" ($url )/v2/_catalog"
301
+ http get - H [authorization $" Basic ($env .REGISTRY_TOKEN )" ] $" ($url )/v2/_catalog"
285
302
} else {
286
- fetch $" ($url )/v2/_catalog"
303
+ http get $" ($url )/v2/_catalog"
287
304
}
288
305
| get repositories
289
306
} else if ($tag | is-empty ) {
290
307
if ($env | has ' REGISTRY_TOKEN' ) {
291
- fetch $" ($url )/v2/($reg )/tags/list"
308
+ http get $" ($url )/v2/($reg )/tags/list"
292
309
} else {
293
- fetch - H [authorization $" Basic ($env .REGISTRY_TOKEN )" ] $" ($url )/v2/($reg )/tags/list"
310
+ http get - H [authorization $" Basic ($env .REGISTRY_TOKEN )" ] $" ($url )/v2/($reg )/tags/list"
294
311
}
295
312
| get tags
296
313
}
@@ -301,10 +318,10 @@ export def "registry list" [
301
318
url : string
302
319
reg : string @" nu-complete registry list"
303
320
] {
304
- if (' REGISTRY_TOKEN' in (env ) .name ) {
305
- fetch - H [authorization $" Basic ($env .REGISTRY_TOKEN )" ] $" ($url )/v2/($reg )/tags/list"
321
+ if (' REGISTRY_TOKEN' in ($ env | columns ) ) {
322
+ http get - H [authorization $" Basic ($env .REGISTRY_TOKEN )" ] $" ($url )/v2/($reg )/tags/list"
306
323
} else {
307
- fetch $" ($url )/v2/($reg )/tags/list"
324
+ http get $" ($url )/v2/($reg )/tags/list"
308
325
}
309
326
| get tags
310
327
}
0 commit comments