upgrade to 0.91 (#776)

update argx.nu, docker.nu, git-v2.nu, kubernetes.nu, ssh.nu, and nvim.nu
to support 0.91 syntax.

---------

Co-authored-by: nash <nash@iffy.me>
This commit is contained in:
fj0r 2024-03-06 20:08:26 +08:00 committed by GitHub
parent 351691f118
commit 0fd766871f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 39 additions and 27 deletions

View File

@ -7,10 +7,10 @@ export def get-sign [cmd] {
mut r = []
for it in $x {
if $it.parameter_type == 'switch' {
if not ($it.short_flag | is-empty) {
if ($it.short_flag | is-not-empty) {
$s ++= $it.short_flag
}
if not ($it.parameter_name | is-empty) {
if ($it.parameter_name | is-not-empty) {
$s ++= $it.parameter_name
}
} else if $it.parameter_type == 'named' {

View File

@ -1,6 +1,6 @@
export-env {
for c in [nerdctl podman docker] {
if not (which $c | is-empty) {
if (which $c | is-not-empty) {
$env.docker-cli = $c
break
}
@ -195,7 +195,7 @@ def "nu-complete docker cp" [cmd: string, offset: int] {
| each {|x| $"($n | get 0):($x)"}
} else {
let files = do -i {
ls -a $"($p)*"
ls -a ($"($p)*" | into glob)
| each {|x| if $x.type == dir { $"($x.name)/"} else { $x.name }}
}
$files | append $ctn
@ -396,7 +396,7 @@ export def container-create [
}
def has [name] {
$name in ($in | columns) and (not ($in | get $name | is-empty))
$name in ($in | columns) and ($in | get $name | is-not-empty)
}
def "nu-complete registry show" [cmd: string, offset: int] {
@ -461,7 +461,7 @@ export def "docker registry delete" [
| str trim
}
print -e $digest
if not ($digest | is-empty) {
if ($digest | is-not-empty) {
curl -sSL -X DELETE ...$header $"($url)/v2/($reg)/manifests/($digest)"
} else {
'not found'

View File

@ -77,12 +77,24 @@ export def gb [
] {
let bs = git branch | lines | each {|x| $x | str substring 2..}
if ($branch | is-empty) {
let d = {
local: (git branch | lines)
remote: (git branch --remote | lines)
no-merged: (git branch --no-merged | lines)
let no_merged = git branch --no-merged | lines | str trim
{
local: (git branch)
remote: (git branch --remote)
}
print ($d | table -i 1 -e)
| transpose k v
| each {|x|
$x.v | lines
| each {|n|
let n = $n | parse -r '\s*(?P<c>\*)?\s*(?P<b>[^\s]+)( -> )?(?P<r>[^\s]+)?' | get 0
let c = if ($n.c | is-empty) { null } else { true }
let r = if ($n.r | is-empty) { null } else { $n.r }
let nm = if $n.b in $no_merged { true } else { null }
let rm = if $x.k == 'remote' { true } else { null }
{ current: $c, remote: $rm, branch: $n.b, ref: $r, no-merged: $nm }
}
}
| flatten
} else if $delete {
if $branch in $bs and (agree 'branch will be delete!') {
git branch -D $branch
@ -318,7 +330,7 @@ export def gr [
git rebase --skip
} else if $quit {
git rebase --quit
} else if not ($onto | is-empty) {
} else if ($onto | is-not-empty) {
git rebase --onto $branch
} else {
let i = if $interactive {[--interactive]} else {[]}

View File

@ -4,7 +4,7 @@ export def ensure-cache-by-lines [cache path action] {
let ls = do -i { open $path | lines | length }
if ($ls | is-empty) { return false }
let lc = do -i { open $cache | get lines}
if not (($cache | path exists) and (not ($lc | is-empty)) and ($ls == $lc)) {
if not (($cache | path exists) and ($lc | is-not-empty) and ($ls == $lc)) {
mkdir ($cache | path dirname)
{
lines: $ls
@ -298,7 +298,7 @@ def "nu-complete kube jsonpath" [context: string] {
let m = kubectl get ...$ns $kind $res $"--output=jsonpath={($p)}" | from json
let l = $row | last
let c = do -i {$m | get $l}
if (not ($c | is-empty)) and ($c | describe | str substring 0..5) == 'table' {
if ($c | is-not-empty) and ($c | describe | str substring 0..5) == 'table' {
$r = (0..(($c | length) - 1) | each {|x| $'($p).($l)[($x)]'})
} else {
$r = ($m | columns | each {|x| $'($p).($x)'})
@ -463,7 +463,7 @@ export def kgp [
--selector (-l): string
--all (-a)
] {
if not ($r | is-empty) {
if ($r | is-not-empty) {
kubectl get pods ...($namespace | with-flag -n) $r --output=json
| from json
| {...$in.metadata, ...$in.spec, ...$in.status}
@ -612,7 +612,7 @@ def "nu-complete kube cp" [cmd: string, offset: int] {
| lines
| each {|x| $"($n | get 0):($x)"}
} else {
let files = do -i { ls -a $"($p)*"
let files = do -i { ls -a ($"($p)*" | into glob)
| each {|x| if $x.type == dir { $"($x.name)/"} else { $x.name }}
}
$files | append $ctn
@ -951,18 +951,18 @@ export def kcmp [--without-service(-s)] {
| each {|z|
let sp = $z.subPath? | default ''
let s = $v | get $z.name
let s = if not ($s.hostPath? | is-empty) {
let s = if ($s.hostPath? | is-not-empty) {
$s.hostPath.path
} else if not ($s.path? | is-empty) {
} else if ($s.path? | is-not-empty) {
$s.path
} else if not ($s.persistentVolumeClaim?.claimName? | is-empty) {
} else if ($s.persistentVolumeClaim?.claimName? | is-not-empty) {
$pvc | get $s.persistentVolumeClaim.claimName
} else if not ($s.configMap?.name? | is-empty) {
} else if ($s.configMap?.name? | is-not-empty) {
['.'
($cm | get $s.configMap.name)
$sp
] | path join
} else if not ($s.secret?.secretName? | is-empty) {
} else if ($s.secret?.secretName? | is-not-empty) {
['.'
($sec | get $s.secret.secretName)
$sp
@ -1059,7 +1059,7 @@ def "nu-complete helm charts" [context: string, offset: int] {
let ctx = $context | argx parse
let path = $ctx | get _pos.chart
let path = if ($path | is-empty) { '.' } else { $path }
let paths = do -i { ls $"($path)*" | each {|x| if $x.type == dir { $"($x.name)/"} else { $x.name }} }
let paths = do -i { ls ($"($path)*" | into glob) | each {|x| if $x.type == dir { $"($x.name)/"} else { $x.name }} }
helm repo list | from ssv -a | rename value description
| append $paths
}

View File

@ -1,8 +1,8 @@
export def ensure-cache [cache paths action] {
mut cfgs = []
for i in $paths {
let cs = (do -i {ls $i})
if not ($cs | is-empty) {
let cs = (do -i {ls ($i | into glob)})
if ($cs | is-not-empty) {
$cfgs = ($cfgs | append $cs)
}
}
@ -120,7 +120,7 @@ def "nu-complete scp" [cmd: string, offset: int] {
| each {|x| $"($n | get 0):($x)"}
} else {
let files = (do -i {
ls -a $"($p)*"
ls -a ($"($p)*" | into glob)
| each {|x| if $x.type == dir { $"($x.name)/"} else { $x.name }}
})
$files | append $ssh

View File

@ -32,7 +32,7 @@
def nvim_tcd [] {
[
{|before, after|
if not ($env.NVIM? | is-empty) {
if ($env.NVIM? | is-not-empty) {
nvim --headless --noplugin --server $env.NVIM --remote-send $"<cmd>lua HookPwdChanged\('($after)', '($before)')<cr>"
}
}
@ -122,7 +122,7 @@ export def nvc [
neovide: [--maximized --server $addr]
}
for g in ($gs | transpose prog args) {
if not (which $g.prog | is-empty) {
if (which $g.prog | is-not-empty) {
^$g.prog ...$g.args
break
}