Skip to content

Commit

Permalink
upgrade to 0.91 (nushell#776)
Browse files Browse the repository at this point in the history
update argx.nu, docker.nu, git-v2.nu, kubernetes.nu, ssh.nu, and nvim.nu
to support 0.91 syntax.

---------

Co-authored-by: nash <[email protected]>
  • Loading branch information
fj0r and nashvi committed Mar 6, 2024
1 parent 351691f commit 0fd7668
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 27 deletions.
4 changes: 2 additions & 2 deletions modules/argx/argx.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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' {
Expand Down
8 changes: 4 additions & 4 deletions modules/docker/docker.nu
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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] {
Expand Down Expand Up @@ -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'
Expand Down
24 changes: 18 additions & 6 deletions modules/git/git-v2.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {[]}
Expand Down
20 changes: 10 additions & 10 deletions modules/kubernetes/kubernetes.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)'})
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions modules/network/ssh.nu
Original file line number Diff line number Diff line change
@@ -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)
}
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/nvim/nvim.nu
Original file line number Diff line number Diff line change
Expand Up @@ -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>"
}
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 0fd7668

Please sign in to comment.