Skip to content

Commit 2024d52

Browse files
fj0ragent
and
agent
authored
upgrade to nu 0.77 (nushell#413)
* auto detect docker cli * rename just to main * upgrade ssh * upgrade kubernetes * upgrade nvim.nu * upgrade git * rename index-need-update to ensure-index * new command `after` --------- Co-authored-by: agent <agent@nuc>
1 parent 10bde06 commit 2024d52

File tree

7 files changed

+136
-107
lines changed

7 files changed

+136
-107
lines changed

after/after.nu

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def "nu-complete ps" [] {
2+
ps | each {|x| { value: $x.pid, description: $x.name } }
3+
}
4+
5+
# after <pid> { do something ... }
6+
export def after [pid: string@"nu-complete ps" action ] {
7+
do -i { tail --pid $pid -f /dev/null }
8+
do $action
9+
}

docker/docker.nu

+73-56
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
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+
}
38
}
49

5-
6-
alias docker = podman
7-
810
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}}"}'
1113
| lines
1214
| each {|x|
1315
let r = ($x | from json)
@@ -17,63 +19,76 @@ export def dp [] {
1719
}
1820

1921
export def di [] {
20-
docker images
22+
^$env.docker-cli images
2123
| from ssv -a
2224
| 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+
}
2439
}
2540

2641
def "nu-complete docker ps" [] {
27-
docker ps
42+
^$env.docker-cli ps
2843
| from ssv -a
2944
| each {|x| {description: $x.NAMES value: $x.'CONTAINER ID'}}
3045
}
3146

3247
def "nu-complete docker container" [] {
33-
docker ps
48+
^$env.docker-cli ps
3449
| from ssv -a
3550
| each {|x| {description: $x.'CONTAINER ID' value: $x.NAMES}}
3651
}
3752

3853
def "nu-complete docker all container" [] {
39-
docker ps -a
54+
^$env.docker-cli ps -a
4055
| from ssv -a
4156
| each {|x| {description: $x.'CONTAINER ID' value: $x.NAMES}}
4257
}
4358

4459
def "nu-complete docker images" [] {
45-
docker images
60+
^$env.docker-cli images
4661
| from ssv
4762
| each {|x| $"($x.REPOSITORY):($x.TAG)"}
4863
}
4964

5065
export def dl [ctn: string@"nu-complete docker container" -n: int = 100] {
5166
let n = if $n == 0 { [] } else { [--tail $n] }
52-
docker logs -f $n $ctn
67+
^$env.docker-cli logs -f $n $ctn
5368
}
5469

5570
export def da [
5671
ctn: string@"nu-complete docker container"
5772
...args
5873
] {
5974
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"
6176
} else {
62-
docker exec -it $ctn $args
77+
^$env.docker-cli exec -it $ctn $args
6378
}
6479
}
6580

6681
def "nu-complete docker cp" [cmd: string, offset: int] {
6782
let argv = ($cmd | str substring [0 $offset] | split row ' ')
6883
let p = if ($argv | length) > 2 { $argv | get 2 } else { $argv | get 1 }
6984
let ctn = (
70-
docker ps
85+
^$env.docker-cli ps
7186
| from ssv -a
7287
| each {|x| {description: $x.'CONTAINER ID' value: $"($x.NAMES):" }}
7388
)
7489
let n = ($p | split row ':')
7590
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)*"
7792
| lines
7893
| each {|x| $"($n | get 0):($x)"}
7994
} else {
@@ -89,66 +104,66 @@ export def dcp [
89104
lhs: string@"nu-complete docker cp",
90105
rhs: string@"nu-complete docker cp"
91106
] {
92-
docker cp $lhs $rhs
107+
^$env.docker-cli cp $lhs $rhs
93108
}
94109

95110
export def dcr [ctn: string@"nu-complete docker all container"] {
96-
docker container rm -f $ctn
111+
^$env.docker-cli container rm -f $ctn
97112
}
98113

99114
export def dis [img: string@"nu-complete docker images"] {
100-
docker inspect $img
115+
^$env.docker-cli inspect $img
101116
}
102117

103118
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
105120
}
106121

107122
export def dsv [...img: string@"nu-complete docker images"] {
108-
docker save $img
123+
^$env.docker-cli save $img
109124
}
110125

111126
export alias dld = podman load
112127

113128
export def dsp [] {
114-
docker system prune -f
129+
^$env.docker-cli system prune -f
115130
}
116131

117132
export alias dspall = podman system prune --all --force --volumes
118133

119134
export def drmi [img: string@"nu-complete docker images"] {
120-
docker rmi $img
135+
^$env.docker-cli rmi $img
121136
}
122137

123138
export def dt [from: string@"nu-complete docker images" to: string] {
124-
docker tag $from $to
139+
^$env.docker-cli tag $from $to
125140
}
126141

127142
export def dps [img: string@"nu-complete docker images"] {
128-
docker push $img
143+
^$env.docker-cli push $img
129144
}
130145

131146
export alias dpl = podman pull
132147

133148
### volume
134149
export def dvl [] {
135-
docker volume ls | from ssv -a
150+
^$env.docker-cli volume ls | from ssv -a
136151
}
137152

138153
def "nu-complete docker volume" [] {
139154
dvl | get name
140155
}
141156

142157
export def dvc [name: string] {
143-
docker volume create
158+
^$env.docker-cli volume create
144159
}
145160

146161
export def dvi [name: string@"nu-complete docker volume"] {
147-
docker volume inspect $name
162+
^$env.docker-cli volume inspect $name
148163
}
149164

150165
export def dvr [...name: string@"nu-complete docker volume"] {
151-
docker volume rm $name
166+
^$env.docker-cli volume rm $name
152167
}
153168

154169
### run
@@ -211,7 +226,7 @@ export def dr [
211226
let netadmin = if $netadmin { [--cap-add=NET_ADMIN --device /dev/net/tun] } else { [] }
212227
let clip = if $with_x { [-e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix] } else { [] }
213228
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)
215230
[-e $"ed25519_($sshuser)=($sshkey)"]
216231
}
217232
let proxy = if ($proxy|is-empty) { [] } else {
@@ -227,7 +242,7 @@ export def dr [
227242
if $dry_run {
228243
echo $"docker run --name ($name) ($args|str join ' ') ($img) ($cmd | flatten)"
229244
} else {
230-
docker run --name $name $args $img ($cmd | flatten)
245+
^$env.docker-cli run --name $name $args $img ($cmd | flatten)
231246
}
232247
}
233248

@@ -247,23 +262,25 @@ export def dx [
247262
...cmd # command args
248263
] {
249264
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+
}
256271
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+
}
267284
let proxy = if ($proxy|is-empty) { [] } else { [--proxy $proxy] }
268285
if $dry_run {
269286
print $"cache: ($c)"
@@ -281,16 +298,16 @@ def "nu-complete registry list" [cmd: string, offset: int] {
281298
let tag = do -i { $cmd | get 4 }
282299
if ($reg|is-empty) {
283300
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"
285302
} else {
286-
fetch $"($url)/v2/_catalog"
303+
http get $"($url)/v2/_catalog"
287304
}
288305
| get repositories
289306
} else if ($tag|is-empty) {
290307
if ($env | has 'REGISTRY_TOKEN') {
291-
fetch $"($url)/v2/($reg)/tags/list"
308+
http get $"($url)/v2/($reg)/tags/list"
292309
} 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"
294311
}
295312
| get tags
296313
}
@@ -301,10 +318,10 @@ export def "registry list" [
301318
url: string
302319
reg: string@"nu-complete registry list"
303320
] {
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"
306323
} else {
307-
fetch $"($url)/v2/($reg)/tags/list"
324+
http get $"($url)/v2/($reg)/tags/list"
308325
}
309326
| get tags
310327
}

git/git.nu

+1-5
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export def glgv [
8080
}
8181

8282
export def gpp! [] {
83+
git pull
8384
git add --all
8485
git commit -v -a --no-edit --amend
8586
git push --force
@@ -111,11 +112,6 @@ export def gm [branch:string@"nu-complete git branches"] {
111112
git merge $branch
112113
}
113114

114-
extern "git reset" [
115-
sha?:string@"nu-complete git log"
116-
--hard:bool
117-
]
118-
119115
export alias gp = git push
120116
export alias gpf! = git push --force
121117
export alias gl = git pull

just/just.nu

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export def "nu-complete just args" [context: string, offset: int] {
3131

3232
}
3333

34-
export extern "just" [
34+
export extern "main" [
3535
recipes?: string@"nu-complete just recipes"
3636
...args: any@"nu-complete just args"
3737
]

0 commit comments

Comments
 (0)