mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-02 07:07:46 +00:00
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:
parent
351691f118
commit
0fd766871f
6 changed files with 39 additions and 27 deletions
|
@ -7,10 +7,10 @@ export def get-sign [cmd] {
|
||||||
mut r = []
|
mut r = []
|
||||||
for it in $x {
|
for it in $x {
|
||||||
if $it.parameter_type == 'switch' {
|
if $it.parameter_type == 'switch' {
|
||||||
if not ($it.short_flag | is-empty) {
|
if ($it.short_flag | is-not-empty) {
|
||||||
$s ++= $it.short_flag
|
$s ++= $it.short_flag
|
||||||
}
|
}
|
||||||
if not ($it.parameter_name | is-empty) {
|
if ($it.parameter_name | is-not-empty) {
|
||||||
$s ++= $it.parameter_name
|
$s ++= $it.parameter_name
|
||||||
}
|
}
|
||||||
} else if $it.parameter_type == 'named' {
|
} else if $it.parameter_type == 'named' {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
export-env {
|
export-env {
|
||||||
for c in [nerdctl podman docker] {
|
for c in [nerdctl podman docker] {
|
||||||
if not (which $c | is-empty) {
|
if (which $c | is-not-empty) {
|
||||||
$env.docker-cli = $c
|
$env.docker-cli = $c
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,7 @@ def "nu-complete docker cp" [cmd: string, offset: int] {
|
||||||
| each {|x| $"($n | get 0):($x)"}
|
| each {|x| $"($n | get 0):($x)"}
|
||||||
} else {
|
} else {
|
||||||
let files = do -i {
|
let files = do -i {
|
||||||
ls -a $"($p)*"
|
ls -a ($"($p)*" | into glob)
|
||||||
| each {|x| if $x.type == dir { $"($x.name)/"} else { $x.name }}
|
| each {|x| if $x.type == dir { $"($x.name)/"} else { $x.name }}
|
||||||
}
|
}
|
||||||
$files | append $ctn
|
$files | append $ctn
|
||||||
|
@ -396,7 +396,7 @@ export def container-create [
|
||||||
}
|
}
|
||||||
|
|
||||||
def has [name] {
|
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] {
|
def "nu-complete registry show" [cmd: string, offset: int] {
|
||||||
|
@ -461,7 +461,7 @@ export def "docker registry delete" [
|
||||||
| str trim
|
| str trim
|
||||||
}
|
}
|
||||||
print -e $digest
|
print -e $digest
|
||||||
if not ($digest | is-empty) {
|
if ($digest | is-not-empty) {
|
||||||
curl -sSL -X DELETE ...$header $"($url)/v2/($reg)/manifests/($digest)"
|
curl -sSL -X DELETE ...$header $"($url)/v2/($reg)/manifests/($digest)"
|
||||||
} else {
|
} else {
|
||||||
'not found'
|
'not found'
|
||||||
|
|
|
@ -77,12 +77,24 @@ export def gb [
|
||||||
] {
|
] {
|
||||||
let bs = git branch | lines | each {|x| $x | str substring 2..}
|
let bs = git branch | lines | each {|x| $x | str substring 2..}
|
||||||
if ($branch | is-empty) {
|
if ($branch | is-empty) {
|
||||||
let d = {
|
let no_merged = git branch --no-merged | lines | str trim
|
||||||
local: (git branch | lines)
|
{
|
||||||
remote: (git branch --remote | lines)
|
local: (git branch)
|
||||||
no-merged: (git branch --no-merged | lines)
|
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 {
|
} else if $delete {
|
||||||
if $branch in $bs and (agree 'branch will be delete!') {
|
if $branch in $bs and (agree 'branch will be delete!') {
|
||||||
git branch -D $branch
|
git branch -D $branch
|
||||||
|
@ -318,7 +330,7 @@ export def gr [
|
||||||
git rebase --skip
|
git rebase --skip
|
||||||
} else if $quit {
|
} else if $quit {
|
||||||
git rebase --quit
|
git rebase --quit
|
||||||
} else if not ($onto | is-empty) {
|
} else if ($onto | is-not-empty) {
|
||||||
git rebase --onto $branch
|
git rebase --onto $branch
|
||||||
} else {
|
} else {
|
||||||
let i = if $interactive {[--interactive]} else {[]}
|
let i = if $interactive {[--interactive]} else {[]}
|
||||||
|
|
|
@ -4,7 +4,7 @@ export def ensure-cache-by-lines [cache path action] {
|
||||||
let ls = do -i { open $path | lines | length }
|
let ls = do -i { open $path | lines | length }
|
||||||
if ($ls | is-empty) { return false }
|
if ($ls | is-empty) { return false }
|
||||||
let lc = do -i { open $cache | get lines}
|
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)
|
mkdir ($cache | path dirname)
|
||||||
{
|
{
|
||||||
lines: $ls
|
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 m = kubectl get ...$ns $kind $res $"--output=jsonpath={($p)}" | from json
|
||||||
let l = $row | last
|
let l = $row | last
|
||||||
let c = do -i {$m | get $l}
|
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)]'})
|
$r = (0..(($c | length) - 1) | each {|x| $'($p).($l)[($x)]'})
|
||||||
} else {
|
} else {
|
||||||
$r = ($m | columns | each {|x| $'($p).($x)'})
|
$r = ($m | columns | each {|x| $'($p).($x)'})
|
||||||
|
@ -463,7 +463,7 @@ export def kgp [
|
||||||
--selector (-l): string
|
--selector (-l): string
|
||||||
--all (-a)
|
--all (-a)
|
||||||
] {
|
] {
|
||||||
if not ($r | is-empty) {
|
if ($r | is-not-empty) {
|
||||||
kubectl get pods ...($namespace | with-flag -n) $r --output=json
|
kubectl get pods ...($namespace | with-flag -n) $r --output=json
|
||||||
| from json
|
| from json
|
||||||
| {...$in.metadata, ...$in.spec, ...$in.status}
|
| {...$in.metadata, ...$in.spec, ...$in.status}
|
||||||
|
@ -612,7 +612,7 @@ def "nu-complete kube cp" [cmd: string, offset: int] {
|
||||||
| lines
|
| lines
|
||||||
| each {|x| $"($n | get 0):($x)"}
|
| each {|x| $"($n | get 0):($x)"}
|
||||||
} else {
|
} 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 }}
|
| each {|x| if $x.type == dir { $"($x.name)/"} else { $x.name }}
|
||||||
}
|
}
|
||||||
$files | append $ctn
|
$files | append $ctn
|
||||||
|
@ -951,18 +951,18 @@ export def kcmp [--without-service(-s)] {
|
||||||
| each {|z|
|
| each {|z|
|
||||||
let sp = $z.subPath? | default ''
|
let sp = $z.subPath? | default ''
|
||||||
let s = $v | get $z.name
|
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
|
$s.hostPath.path
|
||||||
} else if not ($s.path? | is-empty) {
|
} else if ($s.path? | is-not-empty) {
|
||||||
$s.path
|
$s.path
|
||||||
} else if not ($s.persistentVolumeClaim?.claimName? | is-empty) {
|
} else if ($s.persistentVolumeClaim?.claimName? | is-not-empty) {
|
||||||
$pvc | get $s.persistentVolumeClaim.claimName
|
$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)
|
($cm | get $s.configMap.name)
|
||||||
$sp
|
$sp
|
||||||
] | path join
|
] | path join
|
||||||
} else if not ($s.secret?.secretName? | is-empty) {
|
} else if ($s.secret?.secretName? | is-not-empty) {
|
||||||
['.'
|
['.'
|
||||||
($sec | get $s.secret.secretName)
|
($sec | get $s.secret.secretName)
|
||||||
$sp
|
$sp
|
||||||
|
@ -1059,7 +1059,7 @@ def "nu-complete helm charts" [context: string, offset: int] {
|
||||||
let ctx = $context | argx parse
|
let ctx = $context | argx parse
|
||||||
let path = $ctx | get _pos.chart
|
let path = $ctx | get _pos.chart
|
||||||
let path = if ($path | is-empty) { '.' } else { $path }
|
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
|
helm repo list | from ssv -a | rename value description
|
||||||
| append $paths
|
| append $paths
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
export def ensure-cache [cache paths action] {
|
export def ensure-cache [cache paths action] {
|
||||||
mut cfgs = []
|
mut cfgs = []
|
||||||
for i in $paths {
|
for i in $paths {
|
||||||
let cs = (do -i {ls $i})
|
let cs = (do -i {ls ($i | into glob)})
|
||||||
if not ($cs | is-empty) {
|
if ($cs | is-not-empty) {
|
||||||
$cfgs = ($cfgs | append $cs)
|
$cfgs = ($cfgs | append $cs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ def "nu-complete scp" [cmd: string, offset: int] {
|
||||||
| each {|x| $"($n | get 0):($x)"}
|
| each {|x| $"($n | get 0):($x)"}
|
||||||
} else {
|
} else {
|
||||||
let files = (do -i {
|
let files = (do -i {
|
||||||
ls -a $"($p)*"
|
ls -a ($"($p)*" | into glob)
|
||||||
| each {|x| if $x.type == dir { $"($x.name)/"} else { $x.name }}
|
| each {|x| if $x.type == dir { $"($x.name)/"} else { $x.name }}
|
||||||
})
|
})
|
||||||
$files | append $ssh
|
$files | append $ssh
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
def nvim_tcd [] {
|
def nvim_tcd [] {
|
||||||
[
|
[
|
||||||
{|before, after|
|
{|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>"
|
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]
|
neovide: [--maximized --server $addr]
|
||||||
}
|
}
|
||||||
for g in ($gs | transpose prog args) {
|
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
|
^$g.prog ...$g.args
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue