mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 06:37:46 +00:00
kubernetes completion of jsonpath (#487)
* nu-complete kube jsonpath The behavior is correct, but the completion menu cannot be displayed * jsonpath completion for list * New nushell-style git.nu Original renamed to git-classic.nu See `git.md` for details * rename git.md to README.md * Move the helper function to the back * revert power_kube ensure-cache * A more precise description of `gp` * description of behavior that both ahead and behind exist * clean up redundant alias git show can use gl <hash> instead (hash can be completed) * add description of `gl` * add description of gp, ga, gd's parameter * typo: gpc to gcp * description of `gp --override` * rename git.nu to git-v2.nu and git_classic.nu to git.nu * `git fetch` as fallback of `gp` and temporarily disable `gstat` temporarily disable `gstat` in `power_git` because: - `gstat` is not much faster than nushell's implementation of `git_status` - Sometimes the information displayed is inaccurate, but `git_status` parses the output of `git`, which is more reliable - No need to load additional plugins --------- Co-authored-by: agent <agent@nuc> Co-authored-by: nash <nash@iffy.me>
This commit is contained in:
parent
b3ae6f4af0
commit
632a62f035
6 changed files with 646 additions and 27 deletions
|
@ -198,21 +198,54 @@ def "nu-complete kube kind" [] {
|
|||
|
||||
def "nu-complete kube res" [context: string, offset: int] {
|
||||
let ctx = ($context | parse cmd)
|
||||
let def = ($ctx | get args.1)
|
||||
let kind = ($ctx | get args.1)
|
||||
let ns = if ($ctx.-n? | is-empty) { [] } else { [-n $ctx.-n] }
|
||||
kubectl get $ns $def | from ssv -a | get NAME
|
||||
kubectl get $ns $kind | from ssv -a | get NAME
|
||||
}
|
||||
|
||||
def "nu-complete kube res via name" [context: string, offset: int] {
|
||||
let ctx = ($context | parse cmd)
|
||||
let cmd = ($ctx | get args.0)
|
||||
let def = ($env.KUBERNETES_RESOURCE_ABBR | get ($cmd | str substring (($cmd | str length) - 1)..))
|
||||
echo $'($cmd), ($def)' | save -a ~/.nulog
|
||||
let kind = ($env.KUBERNETES_RESOURCE_ABBR | get ($ctx | get args.0 | str substring (-1..)))
|
||||
let ns = if ($ctx.-n? | is-empty) { [] } else { [-n $ctx.-n] }
|
||||
kubectl get $ns $def | from ssv -a | get NAME
|
||||
kubectl get $ns $kind | from ssv -a | get NAME
|
||||
}
|
||||
|
||||
def "nu-complete kube path" [context: string, offset: int] {
|
||||
export def "nu-complete kube jsonpath" [context: string] {
|
||||
let ctx = ($context | parse cmd)
|
||||
let kind = ($ctx | get args.1)
|
||||
let res = ($ctx | get args.2)
|
||||
let path = $ctx.-p?
|
||||
let ns = if ($ctx.-n? | is-empty) { [] } else { [-n $ctx.-n] }
|
||||
mut r = []
|
||||
if ($path | is-empty) {
|
||||
if ($context | str ends-with '-p ') {
|
||||
$r = ['.']
|
||||
} else {
|
||||
$r = ['']
|
||||
}
|
||||
} else if ($path | str starts-with '.') {
|
||||
let row = ($path | split row '.')
|
||||
let p = ($row | range ..-2 | str join '.')
|
||||
if ($p | is-empty) {
|
||||
$r = ( kubectl get $ns -o json $kind $res
|
||||
| from json
|
||||
| columns
|
||||
| each {|x| $'($p).($x)'}
|
||||
)
|
||||
} else {
|
||||
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' {
|
||||
$r = (0..(($c | length) - 1) | each {|x| $'($p).($l)[($x)]'})
|
||||
} else {
|
||||
$r = ($m | columns | each {|x| $'($p).($x)'})
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$r = ['']
|
||||
}
|
||||
$r
|
||||
}
|
||||
|
||||
# kubectl get
|
||||
|
@ -220,7 +253,7 @@ export def kg [
|
|||
k: string@"nu-complete kube kind"
|
||||
r?: string@"nu-complete kube res"
|
||||
--namespace (-n): string@"nu-complete kube ns"
|
||||
--jsonpath (-p): string@"nu-complete kube path"
|
||||
--jsonpath (-p): string@"nu-complete kube jsonpath"
|
||||
--selector (-l): string
|
||||
--verbose (-v): bool
|
||||
--watch (-w): bool
|
||||
|
@ -255,7 +288,7 @@ export def kg [
|
|||
kubectl get $n $k $r | from ssv -a
|
||||
}
|
||||
} else {
|
||||
kubectl get $n $k $r $"--output=jsonpath={($jsonpath)}" | from yaml
|
||||
kubectl get $n $k $r $"--output=jsonpath={($jsonpath)}" | from json
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -339,7 +372,7 @@ def "nu-complete kube ctns" [context: string, offset: int] {
|
|||
export def kgp [
|
||||
r?: string@"nu-complete kube res via name"
|
||||
--namespace (-n): string@"nu-complete kube ns"
|
||||
--jsonpath (-p): string@"nu-complete kube path"
|
||||
--jsonpath (-p): string@"nu-complete kube jsonpath"
|
||||
--selector (-l): string
|
||||
] {
|
||||
kg pods -n $namespace -p $jsonpath -l $selector $r
|
||||
|
@ -439,7 +472,7 @@ export def kcp [
|
|||
export def kgs [
|
||||
r?: string@"nu-complete kube res via name"
|
||||
--namespace (-n): string@"nu-complete kube ns"
|
||||
--jsonpath (-p): string@"nu-complete kube path"
|
||||
--jsonpath (-p): string@"nu-complete kube jsonpath"
|
||||
--selector (-l): string
|
||||
] {
|
||||
kg services -n $namespace -p $jsonpath -l $selector $r
|
||||
|
@ -459,7 +492,7 @@ export def kdels [svc: string@"nu-complete kube res via name", -n: string@"nu-co
|
|||
export def kgd [
|
||||
r?: string@"nu-complete kube res via name"
|
||||
--namespace (-n): string@"nu-complete kube ns"
|
||||
--jsonpath (-p): string@"nu-complete kube path"
|
||||
--jsonpath (-p): string@"nu-complete kube jsonpath"
|
||||
--selector (-l): string
|
||||
] {
|
||||
kg -n $namespace deployments -p $jsonpath -l $selector $r
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue