mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-02 23:27:45 +00:00
parent
0632778754
commit
30d386e363
5 changed files with 190 additions and 152 deletions
|
@ -45,7 +45,9 @@ module utils {
|
||||||
$r
|
$r
|
||||||
}
|
}
|
||||||
|
|
||||||
export def 'os type' [] {
|
export def distro [] {
|
||||||
|
match $nu.os-info.name {
|
||||||
|
'linux' => {
|
||||||
let info = cat /etc/os-release
|
let info = cat /etc/os-release
|
||||||
| lines
|
| lines
|
||||||
| reduce -f {} {|x, acc|
|
| reduce -f {} {|x, acc|
|
||||||
|
@ -62,6 +64,11 @@ module utils {
|
||||||
$info.ID
|
$info.ID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_ => {
|
||||||
|
$nu.os-info.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export def outdent [] {
|
export def outdent [] {
|
||||||
let txt = $in | lines | range 1..
|
let txt = $in | lines | range 1..
|
||||||
|
@ -257,7 +264,7 @@ module run {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export def main [tbl --watch: bool] {
|
export def main [tbl --opt: record] {
|
||||||
let n = $in
|
let n = $in
|
||||||
use tree
|
use tree
|
||||||
use resolve
|
use resolve
|
||||||
|
@ -268,7 +275,7 @@ module run {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let flt = if $_.flt in $n.node { [...$n.filter ...($n.node | get $_.flt)] } else { $n.filter }
|
let flt = if $_.flt in $n.node { [...$n.filter ...($n.node | get $_.flt)] } else { $n.filter }
|
||||||
let wth = if $watch {
|
let wth = if $opt.watch {
|
||||||
if $_.wth in $n.node {
|
if $_.wth in $n.node {
|
||||||
[...$n.watch ($n.node | get $_.watch)]
|
[...$n.watch ($n.node | get $_.watch)]
|
||||||
} else {
|
} else {
|
||||||
|
@ -495,7 +502,7 @@ module test {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export def run [tbl --watch: bool] {
|
export def run [tbl --opt: record] {
|
||||||
let argv = $in
|
let argv = $in
|
||||||
let _ = $env.comma_index
|
let _ = $env.comma_index
|
||||||
use tree
|
use tree
|
||||||
|
@ -540,7 +547,7 @@ module test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
| tree map $cb $bc
|
| tree map $cb $bc
|
||||||
if ($watch | default false) {
|
if ($opt.watch? | default false) {
|
||||||
use run watches
|
use run watches
|
||||||
watches {
|
watches {
|
||||||
$specs | suit
|
$specs | suit
|
||||||
|
@ -552,9 +559,9 @@ module test {
|
||||||
}
|
}
|
||||||
|
|
||||||
module vscode-tasks {
|
module vscode-tasks {
|
||||||
export def merge [args tbl --json: bool] {
|
export def merge [args tbl --opt: record] {
|
||||||
let c = $args | gen $tbl
|
let c = $args | gen $tbl
|
||||||
if $json {
|
if $opt.json {
|
||||||
$c | to json
|
$c | to json
|
||||||
} else {
|
} else {
|
||||||
$c
|
$c
|
||||||
|
@ -669,10 +676,6 @@ def 'find parent' [] {
|
||||||
|
|
||||||
def 'comma file' [] {
|
def 'comma file' [] {
|
||||||
[
|
[
|
||||||
{
|
|
||||||
condition: {|_, after| not ($after | path join ',.nu' | path exists)}
|
|
||||||
code: "$env.comma = null"
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
condition: {|_, after| $after | path join ',.nu' | path exists}
|
condition: {|_, after| $after | path join ',.nu' | path exists}
|
||||||
code: "
|
code: "
|
||||||
|
@ -753,8 +756,7 @@ export-env {
|
||||||
watch_separator: $"(ansi dark_gray)------------------------------(ansi reset)"
|
watch_separator: $"(ansi dark_gray)------------------------------(ansi reset)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
os: (os type)
|
distro: (distro)
|
||||||
arch: (uname -m)
|
|
||||||
lg: {$in | lg}
|
lg: {$in | lg}
|
||||||
batch: {|mod|
|
batch: {|mod|
|
||||||
let o = $in
|
let o = $in
|
||||||
|
@ -850,13 +852,18 @@ def expose [t, a, tbl] {
|
||||||
}
|
}
|
||||||
|
|
||||||
# perform or print
|
# perform or print
|
||||||
export def --wrapped pp [...x --print] {
|
export def --wrapped pp [...x --print --as-str] {
|
||||||
if $print or (do -i { $env.comma_index | get $env.comma_index.dry_run } | default false) {
|
if $print or (do -i { $env.comma_index | get $env.comma_index.dry_run } | default false) {
|
||||||
use run
|
use run
|
||||||
run dry $x --strip
|
let r = run dry $x --strip
|
||||||
|
if $as_str {
|
||||||
|
$r
|
||||||
|
} else {
|
||||||
|
print -e $"(ansi light_gray)($r)(ansi reset)(char newline)"
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
use tree spread
|
use tree spread
|
||||||
^$x.0 (spread ($x | range 1..))
|
^$x.0 ...(spread ($x | range 1..))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -884,7 +891,7 @@ export def --wrapped , [
|
||||||
if ($args | is-empty) {
|
if ($args | is-empty) {
|
||||||
if $vscode {
|
if $vscode {
|
||||||
use vscode-tasks
|
use vscode-tasks
|
||||||
vscode-tasks merge $args (resolve comma) --json $json
|
vscode-tasks merge $args (resolve comma) --opt {json: $json}
|
||||||
} else if ([$env.PWD, ',.nu'] | path join | path exists) {
|
} else if ([$env.PWD, ',.nu'] | path join | path exists) {
|
||||||
^$env.EDITOR ,.nu
|
^$env.EDITOR ,.nu
|
||||||
} else {
|
} else {
|
||||||
|
@ -921,7 +928,7 @@ export def --wrapped , [
|
||||||
}
|
}
|
||||||
} else if $test {
|
} else if $test {
|
||||||
use test
|
use test
|
||||||
$args | flatten | test run $tbl --watch $watch
|
$args | flatten | test run $tbl --opt {watch: $watch}
|
||||||
} else if $expose {
|
} else if $expose {
|
||||||
expose $args.0 ($args | range 1..) $tbl
|
expose $args.0 ($args | range 1..) $tbl
|
||||||
} else {
|
} else {
|
||||||
|
@ -929,7 +936,7 @@ export def --wrapped , [
|
||||||
$env.comma_index = ($env.comma_index | upsert $env.comma_index.dry_run true)
|
$env.comma_index = ($env.comma_index | upsert $env.comma_index.dry_run true)
|
||||||
}
|
}
|
||||||
use run
|
use run
|
||||||
$args | flatten | run $tbl --watch $watch
|
$args | flatten | run $tbl --opt {watch: $watch}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,13 +31,9 @@ $env.comma = {|_|{
|
||||||
$_.a: {, suit dry_run a }
|
$_.a: {, suit dry_run a }
|
||||||
$_.x: {|r| ($r | lines | get 0) == $env.PWD }
|
$_.x: {|r| ($r | lines | get 0) == $env.PWD }
|
||||||
}
|
}
|
||||||
yes: {
|
pp: {
|
||||||
$_.a: {, -p suit dry_run a }
|
|
||||||
$_.x: {|r| $r == 'pwd'}
|
|
||||||
}
|
|
||||||
ee: {
|
|
||||||
$_.a: {
|
$_.a: {
|
||||||
pp --print aaa bbbb ccccc dddddd eeeeee [
|
pp --print --as-str aaa bbbb ccccc dddddd eeeeee [
|
||||||
ffffff gggggggggg [
|
ffffff gggggggggg [
|
||||||
hhhhhhhhh iiiiiiiiii lllllllll
|
hhhhhhhhh iiiiiiiiii lllllllll
|
||||||
] mmmmmmmmmmmmm nnnnnnnnnnnn
|
] mmmmmmmmmmmmm nnnnnnnnnnnn
|
||||||
|
|
|
@ -32,15 +32,17 @@ def "nu-complete docker ns" [] {
|
||||||
}
|
}
|
||||||
|
|
||||||
# list containers
|
# list containers
|
||||||
export def container-process-list [
|
export def container-list [
|
||||||
-n: string@"nu-complete docker ns"
|
-n: string@"nu-complete docker ns"
|
||||||
container?: string@"nu-complete docker containers"
|
container?: string@"nu-complete docker containers"
|
||||||
|
--all(-a)
|
||||||
] {
|
] {
|
||||||
let cli = $env.docker-cli
|
let cli = $env.docker-cli
|
||||||
if ($container | is-empty) {
|
if ($container | is-empty) {
|
||||||
let fmt = '{"id":"{{.ID}}", "image": "{{.Image}}", "name":"{{.Names}}", "cmd":{{.Command}}, "port":"{{.Ports}}", "status":"{{.Status}}", "created":"{{.CreatedAt}}"}'
|
let fmt = '{"id":"{{.ID}}", "image": "{{.Image}}", "name":"{{.Names}}", "cmd":{{.Command}}, "port":"{{.Ports}}", "status":"{{.Status}}", "created":"{{.CreatedAt}}"}'
|
||||||
let fmt = if $cli == 'podman' { $fmt | str replace '{{.Command}}' '"{{.Command}}"' | str replace '{{.CreatedAt}}' '{{.Created}}' } else { $fmt }
|
let fmt = if $cli == 'podman' { $fmt | str replace '{{.Command}}' '"{{.Command}}"' | str replace '{{.CreatedAt}}' '{{.Created}}' } else { $fmt }
|
||||||
^$cli ps -a --format $fmt
|
let all = if $all {[-a]} else {[]}
|
||||||
|
^$cli ps ...$all --format $fmt
|
||||||
| lines
|
| lines
|
||||||
| each {|x|
|
| each {|x|
|
||||||
let r = $x | from json
|
let r = $x | from json
|
||||||
|
@ -48,11 +50,11 @@ export def container-process-list [
|
||||||
$r | upsert created $t
|
$r | upsert created $t
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let r = ^$cli ($n | with-flag -n) inspect $container
|
let r = ^$cli ...($n | with-flag -n) inspect $container
|
||||||
| from json
|
| from json
|
||||||
| get 0
|
| get 0
|
||||||
let image = $r.Image
|
let image = $r.Image
|
||||||
let img = ^$cli ($n | with-flag -n) inspect $image
|
let img = ^$cli ...($n | with-flag -n) inspect $image
|
||||||
| from json
|
| from json
|
||||||
| get 0
|
| get 0
|
||||||
let imgEnv = $img.Config.Env?
|
let imgEnv = $img.Config.Env?
|
||||||
|
@ -89,7 +91,7 @@ export def image-list [
|
||||||
img?: string@"nu-complete docker images"
|
img?: string@"nu-complete docker images"
|
||||||
] {
|
] {
|
||||||
if ($img | is-empty) {
|
if ($img | is-empty) {
|
||||||
^$env.docker-cli ($n | with-flag -n) images
|
^$env.docker-cli ...($n | with-flag -n) images
|
||||||
| from ssv -a
|
| from ssv -a
|
||||||
| each {|x|
|
| each {|x|
|
||||||
let size = $x.SIZE | into filesize
|
let size = $x.SIZE | into filesize
|
||||||
|
@ -106,7 +108,7 @@ export def image-list [
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let r = ^$env.docker-cli ($n | with-flag -n) inspect $img
|
let r = ^$env.docker-cli ...($n | with-flag -n) inspect $img
|
||||||
| from json
|
| from json
|
||||||
| get 0
|
| get 0
|
||||||
let e = $r.Config.Env?
|
let e = $r.Config.Env?
|
||||||
|
@ -167,7 +169,7 @@ export def container-log-namespace [ctn: string@"nu-complete docker containers"
|
||||||
-n: string@"nu-complete docker ns" # namespace
|
-n: string@"nu-complete docker ns" # namespace
|
||||||
] {
|
] {
|
||||||
let l = if $l == 0 { [] } else { [--tail $l] }
|
let l = if $l == 0 { [] } else { [--tail $l] }
|
||||||
^$env.docker-cli ($n | with-flag -n) logs -f $l $ctn
|
^$env.docker-cli ...($n | with-flag -n) logs -f $l $ctn
|
||||||
}
|
}
|
||||||
|
|
||||||
# attach container
|
# attach container
|
||||||
|
@ -178,9 +180,9 @@ export def container-attach [
|
||||||
] {
|
] {
|
||||||
let ns = $n | with-flag -n
|
let ns = $n | with-flag -n
|
||||||
if ($args|is-empty) {
|
if ($args|is-empty) {
|
||||||
^$env.docker-cli $ns exec -it $ctn /bin/sh -c "[ -e /bin/zsh ] && /bin/zsh || [ -e /bin/bash ] && /bin/bash || /bin/sh"
|
^$env.docker-cli ...$ns exec -it $ctn /bin/sh -c "[ -e /bin/zsh ] && /bin/zsh || [ -e /bin/bash ] && /bin/bash || /bin/sh"
|
||||||
} else {
|
} else {
|
||||||
^$env.docker-cli $ns exec -it $ctn $args
|
^$env.docker-cli ...$ns exec -it $ctn ...$args
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,61 +216,61 @@ export def container-copy-file [
|
||||||
|
|
||||||
# remove container
|
# remove container
|
||||||
export def container-remove [ctn: string@"nu-complete docker all containers" -n: string@"nu-complete docker ns"] {
|
export def container-remove [ctn: string@"nu-complete docker all containers" -n: string@"nu-complete docker ns"] {
|
||||||
^$env.docker-cli ($n | with-flag -n) container rm -f $ctn
|
^$env.docker-cli ...($n | with-flag -n) container rm -f $ctn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# history
|
# history
|
||||||
export def container-history [img: string@"nu-complete docker images" -n: string@"nu-complete docker ns"] {
|
export def container-history [img: string@"nu-complete docker images" -n: string@"nu-complete docker ns"] {
|
||||||
^$env.docker-cli ($n | with-flag -n) history --no-trunc $img | from ssv -a
|
^$env.docker-cli ...($n | with-flag -n) history --no-trunc $img | from ssv -a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# save images
|
# save images
|
||||||
export def image-save [-n: string@"nu-complete docker ns" ...img: string@"nu-complete docker images"] {
|
export def image-save [-n: string@"nu-complete docker ns" ...img: string@"nu-complete docker images"] {
|
||||||
^$env.docker-cli ($n | with-flag -n) save $img
|
^$env.docker-cli ...($n | with-flag -n) save $img
|
||||||
}
|
}
|
||||||
|
|
||||||
# load images
|
# load images
|
||||||
export def image-load [-n: string@"nu-complete docker ns"] {
|
export def image-load [-n: string@"nu-complete docker ns"] {
|
||||||
^$env.docker-cli ($n | with-flag -n) load
|
^$env.docker-cli ...($n | with-flag -n) load
|
||||||
}
|
}
|
||||||
|
|
||||||
# system prune
|
# system prune
|
||||||
export def system-prune [-n: string@"nu-complete docker ns"] {
|
export def system-prune [-n: string@"nu-complete docker ns"] {
|
||||||
^$env.docker-cli ($n | with-flag -n) system prune -f
|
^$env.docker-cli ...($n | with-flag -n) system prune -f
|
||||||
}
|
}
|
||||||
|
|
||||||
# system prune all
|
# system prune all
|
||||||
export def system-prune-all [-n: string@"nu-complete docker ns"] {
|
export def system-prune-all [-n: string@"nu-complete docker ns"] {
|
||||||
^$env.docker-cli ($n | with-flag -n) system prune --all --force --volumes
|
^$env.docker-cli ...($n | with-flag -n) system prune --all --force --volumes
|
||||||
}
|
}
|
||||||
|
|
||||||
# remove image
|
# remove image
|
||||||
export def image-remove [img: string@"nu-complete docker images" -n: string@"nu-complete docker ns"] {
|
export def image-remove [img: string@"nu-complete docker images" -n: string@"nu-complete docker ns"] {
|
||||||
^$env.docker-cli ($n | with-flag -n) rmi $img
|
^$env.docker-cli ...($n | with-flag -n) rmi $img
|
||||||
}
|
}
|
||||||
|
|
||||||
# add new tag
|
# add new tag
|
||||||
export def image-tag [from: string@"nu-complete docker images" to: string -n: string@"nu-complete docker ns"] {
|
export def image-tag [from: string@"nu-complete docker images" to: string -n: string@"nu-complete docker ns"] {
|
||||||
^$env.docker-cli ($n | with-flag -n) tag $from $to
|
^$env.docker-cli ...($n | with-flag -n) tag $from $to
|
||||||
}
|
}
|
||||||
|
|
||||||
# push image
|
# push image
|
||||||
export def image-push [img: string@"nu-complete docker images" -n: string@"nu-complete docker ns" -i] {
|
export def image-push [img: string@"nu-complete docker images" -n: string@"nu-complete docker ns" -i] {
|
||||||
let $insecure = if $i {[--insecure-registry]} else {[]}
|
let $insecure = if $i {[--insecure-registry]} else {[]}
|
||||||
^$env.docker-cli ($n | with-flag -n) $insecure push $img
|
^$env.docker-cli ...($n | with-flag -n) $insecure push $img
|
||||||
}
|
}
|
||||||
|
|
||||||
# pull image
|
# pull image
|
||||||
export def image-pull [img -n: string@"nu-complete docker ns" -i] {
|
export def image-pull [img -n: string@"nu-complete docker ns" -i] {
|
||||||
let $insecure = if $i {[--insecure-registry]} else {[]}
|
let $insecure = if $i {[--insecure-registry]} else {[]}
|
||||||
^$env.docker-cli ($n | with-flag -n) $insecure pull $img
|
^$env.docker-cli ...($n | with-flag -n) $insecure pull $img
|
||||||
}
|
}
|
||||||
|
|
||||||
### list volume
|
### list volume
|
||||||
export def volume-list [-n: string@"nu-complete docker ns"] {
|
export def volume-list [-n: string@"nu-complete docker ns"] {
|
||||||
^$env.docker-cli ($n | with-flag -n) volume ls | from ssv -a
|
^$env.docker-cli ...($n | with-flag -n) volume ls | from ssv -a
|
||||||
}
|
}
|
||||||
|
|
||||||
def "nu-complete docker volume" [] {
|
def "nu-complete docker volume" [] {
|
||||||
|
@ -277,17 +279,17 @@ def "nu-complete docker volume" [] {
|
||||||
|
|
||||||
# create volume
|
# create volume
|
||||||
export def volume-create [name: string -n: string@"nu-complete docker ns"] {
|
export def volume-create [name: string -n: string@"nu-complete docker ns"] {
|
||||||
^$env.docker-cli ($n | with-flag -n) volume create
|
^$env.docker-cli ...($n | with-flag -n) volume create
|
||||||
}
|
}
|
||||||
|
|
||||||
# inspect volume
|
# inspect volume
|
||||||
export def volume-inspect [name: string@"nu-complete docker volume" -n: string@"nu-complete docker ns"] {
|
export def volume-inspect [name: string@"nu-complete docker volume" -n: string@"nu-complete docker ns"] {
|
||||||
^$env.docker-cli ($n | with-flag -n) volume inspect $name
|
^$env.docker-cli ...($n | with-flag -n) volume inspect $name
|
||||||
}
|
}
|
||||||
|
|
||||||
# remove volume
|
# remove volume
|
||||||
export def volume-remove [...name: string@"nu-complete docker volume" -n: string@"nu-complete docker ns"] {
|
export def volume-remove [...name: string@"nu-complete docker volume" -n: string@"nu-complete docker ns"] {
|
||||||
^$env.docker-cli ($n | with-flag -n) volume rm $name
|
^$env.docker-cli ...($n | with-flag -n) volume rm $name
|
||||||
}
|
}
|
||||||
|
|
||||||
### run
|
### run
|
||||||
|
@ -382,7 +384,7 @@ export def container-create [
|
||||||
echo ([docker $ns run --name $name $args $img $cmd] | flatten | str join ' ')
|
echo ([docker $ns run --name $name $args $img $cmd] | flatten | str join ' ')
|
||||||
} else {
|
} else {
|
||||||
let $img = if $env.docker-cli == 'nerdctl' { local_image $img } else { $img }
|
let $img = if $env.docker-cli == 'nerdctl' { local_image $img } else { $img }
|
||||||
^$env.docker-cli $ns run --name $name $args $img ($cmd | flatten)
|
^$env.docker-cli ...$ns run --name $name ...$args $img ...($cmd | flatten)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,10 +404,10 @@ def "nu-complete registry show" [cmd: string, offset: int] {
|
||||||
[]
|
[]
|
||||||
}
|
}
|
||||||
if ($tag | is-empty) and (not $new) or ($reg | is-empty) {
|
if ($tag | is-empty) and (not $new) or ($reg | is-empty) {
|
||||||
curl -sSL $auth $"($url)/v2/_catalog"
|
curl -sSL ...$auth $"($url)/v2/_catalog"
|
||||||
| from json | get repositories
|
| from json | get repositories
|
||||||
} else {
|
} else {
|
||||||
curl -sSL $auth $"($url)/v2/($reg)/tags/list"
|
curl -sSL ...$auth $"($url)/v2/($reg)/tags/list"
|
||||||
| from json | get tags
|
| from json | get tags
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -422,11 +424,11 @@ export def "registry show" [
|
||||||
[]
|
[]
|
||||||
}
|
}
|
||||||
if ($reg | is-empty) {
|
if ($reg | is-empty) {
|
||||||
curl -sSL $auth $"($url)/v2/_catalog" | from json | get repositories
|
curl -sSL ...$auth $"($url)/v2/_catalog" | from json | get repositories
|
||||||
} else if ($tag | is-empty) {
|
} else if ($tag | is-empty) {
|
||||||
curl -sSL $auth $"($url)/v2/($reg)/tags/list" | from json | get tags
|
curl -sSL ...$auth $"($url)/v2/($reg)/tags/list" | from json | get tags
|
||||||
} else {
|
} else {
|
||||||
curl -sSL -H 'Accept: application/vnd.oci.image.manifest.v1+json' $auth $"($url)/v2/($reg)/manifests/($tag)" | from json
|
curl -sSL -H 'Accept: application/vnd.oci.image.manifest.v1+json' ...$auth $"($url)/v2/($reg)/manifests/($tag)" | from json
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,7 +465,7 @@ export def "bud rm" [
|
||||||
buildah rm $id
|
buildah rm $id
|
||||||
}
|
}
|
||||||
|
|
||||||
export alias dp = container-process-list
|
export alias dp = container-list
|
||||||
export alias di = image-list
|
export alias di = image-list
|
||||||
export alias dl = container-log
|
export alias dl = container-log
|
||||||
export alias dln = container-log-namespace
|
export alias dln = container-log-namespace
|
||||||
|
|
|
@ -45,7 +45,7 @@ export def gst [
|
||||||
} else if $show {
|
} else if $show {
|
||||||
git stash show --text
|
git stash show --text
|
||||||
} else if $all {
|
} else if $all {
|
||||||
git stash --all (if $include_untracked {[--include-untracked]} else {[]})
|
git stash --all ...(if $include_untracked {[--include-untracked]} else {[]})
|
||||||
} else {
|
} else {
|
||||||
git stash
|
git stash
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ export def --env gn [
|
||||||
} else {
|
} else {
|
||||||
$local
|
$local
|
||||||
}
|
}
|
||||||
git clone (if $submodule {[--recurse-submodules]} else {[]}) $repo $local
|
git clone ...(if $submodule {[--recurse-submodules]} else {[]}) $repo $local
|
||||||
cd $local
|
cd $local
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,14 +170,14 @@ export def gp [
|
||||||
print $'* switch to ($branch)'
|
print $'* switch to ($branch)'
|
||||||
git checkout $branch
|
git checkout $branch
|
||||||
}
|
}
|
||||||
git pull $m $a
|
git pull ...$m ...$a
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print "* local doesn't have that branch, fetch"
|
print "* local doesn't have that branch, fetch"
|
||||||
git checkout -b $branch
|
git checkout -b $branch
|
||||||
git fetch $remote $branch
|
git fetch $remote $branch
|
||||||
git branch -u $'($remote)/($branch)' $branch
|
git branch -u $'($remote)/($branch)' $branch
|
||||||
git pull $m $a -v
|
git pull ...$m ...$a -v
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let bmsg = "* remote doesn't have that branch"
|
let bmsg = "* remote doesn't have that branch"
|
||||||
|
@ -221,19 +221,19 @@ export def ga [
|
||||||
if $delete {
|
if $delete {
|
||||||
let c = if $cached {[--cached]} else {[]}
|
let c = if $cached {[--cached]} else {[]}
|
||||||
let f = if $force {[--force]} else {[]}
|
let f = if $force {[--force]} else {[]}
|
||||||
git rm $c $f -r $file
|
git rm ...$c ...$f -r ...$file
|
||||||
} else if $restore {
|
} else if $restore {
|
||||||
let o = $source | with-flag --source
|
let o = $source | with-flag --source
|
||||||
let s = if $staged {[--staged]} else {[]}
|
let s = if $staged {[--staged]} else {[]}
|
||||||
let file = if ($file | is-empty) { [.] } else { [$file] }
|
let file = if ($file | is-empty) { [.] } else { [$file] }
|
||||||
git restore $o $s $file
|
git restore ...$o ...$s ...$file
|
||||||
} else {
|
} else {
|
||||||
let a = if $all {[--all]} else {[]}
|
let a = if $all {[--all]} else {[]}
|
||||||
let p = if $patch {[--patch]} else {[]}
|
let p = if $patch {[--patch]} else {[]}
|
||||||
let u = if $update {[--update]} else {[]}
|
let u = if $update {[--update]} else {[]}
|
||||||
let v = if $verbose {[--verbose]} else {[]}
|
let v = if $verbose {[--verbose]} else {[]}
|
||||||
let file = if ($file | is-empty) { [.] } else { [$file] }
|
let file = if ($file | is-empty) { [.] } else { [$file] }
|
||||||
git add $a $p $u $v $file
|
git add ...$a ...$p ...$u ...$v ...$file
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -249,7 +249,7 @@ export def gc [
|
||||||
let a = if $all {[--all]} else {[]}
|
let a = if $all {[--all]} else {[]}
|
||||||
let n = if $amend {[--amend]} else {[]}
|
let n = if $amend {[--amend]} else {[]}
|
||||||
let k = if $keep {[--no-edit]} else {[]}
|
let k = if $keep {[--no-edit]} else {[]}
|
||||||
git commit -v $m $a $n $k
|
git commit -v ...$m ...$a ...$n ...$k
|
||||||
}
|
}
|
||||||
|
|
||||||
# git diff
|
# git diff
|
||||||
|
@ -262,7 +262,7 @@ export def gd [
|
||||||
let w = if $word_diff {[--word-diff]} else {[]}
|
let w = if $word_diff {[--word-diff]} else {[]}
|
||||||
let c = if $cached {[--cached]} else {[]}
|
let c = if $cached {[--cached]} else {[]}
|
||||||
let s = if $staged {[--staged]} else {[]}
|
let s = if $staged {[--staged]} else {[]}
|
||||||
git diff $c $s $w ($file | with-flag)
|
git diff ...$c ...$s ...$w ...($file | with-flag)
|
||||||
}
|
}
|
||||||
|
|
||||||
# git merge
|
# git merge
|
||||||
|
@ -275,9 +275,9 @@ export def gm [
|
||||||
] {
|
] {
|
||||||
let x = if $no_squash { [] } else { [--squash] }
|
let x = if $no_squash { [] } else { [--squash] }
|
||||||
if ($branch | is-empty) {
|
if ($branch | is-empty) {
|
||||||
git merge $x $"origin/(git_main_branch)"
|
git merge ...$x $"origin/(git_main_branch)"
|
||||||
} else {
|
} else {
|
||||||
git merge $x $branch
|
git merge ...$x $branch
|
||||||
}
|
}
|
||||||
if not $no_squash {
|
if not $no_squash {
|
||||||
git commit -v
|
git commit -v
|
||||||
|
@ -308,9 +308,9 @@ export def gr [
|
||||||
} else {
|
} else {
|
||||||
let i = if $interactive {[--interactive]} else {[]}
|
let i = if $interactive {[--interactive]} else {[]}
|
||||||
if ($branch | is-empty) {
|
if ($branch | is-empty) {
|
||||||
git rebase $i (git_main_branch)
|
git rebase ...$i (git_main_branch)
|
||||||
} else {
|
} else {
|
||||||
git rebase $i $branch
|
git rebase ...$i $branch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -352,7 +352,7 @@ export def grs [
|
||||||
] {
|
] {
|
||||||
let h = if $hard {[--hard]} else {[]}
|
let h = if $hard {[--hard]} else {[]}
|
||||||
let cm = $commit | with-flag
|
let cm = $commit | with-flag
|
||||||
git reset $h $cm
|
git reset ...$h ...$cm
|
||||||
if $clean {
|
if $clean {
|
||||||
git clean -fd
|
git clean -fd
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,6 +198,25 @@ export def 'kconf import' [name: string, path: string] {
|
||||||
}
|
}
|
||||||
|
|
||||||
export def 'kconf delete' [name: string@"nu-complete kube ctx"] {
|
export def 'kconf delete' [name: string@"nu-complete kube ctx"] {
|
||||||
|
let kc = (kube-config)
|
||||||
|
let d = $kc.data
|
||||||
|
let ctx = $d | get contexts | where name == $name | get 0
|
||||||
|
let rctx = $d | get contexts | where name != $name
|
||||||
|
let user = if ($ctx.context.user in ($rctx | get context.user)) {
|
||||||
|
$d | get users
|
||||||
|
} else {
|
||||||
|
$d | get users | where name != $ctx.context.user
|
||||||
|
}
|
||||||
|
let cluster = if ($ctx.context.cluster in ($rctx | get context.cluster)) {
|
||||||
|
$d | get clusters
|
||||||
|
} else {
|
||||||
|
$d | get clusters | where name != $ctx.context.cluster
|
||||||
|
}
|
||||||
|
$d
|
||||||
|
| update contexts $rctx
|
||||||
|
| update users $user
|
||||||
|
| update clusters $cluster
|
||||||
|
| to yaml
|
||||||
}
|
}
|
||||||
|
|
||||||
export def 'kconf export' [name: string@"nu-complete kube ctx"] {
|
export def 'kconf export' [name: string@"nu-complete kube ctx"] {
|
||||||
|
@ -243,14 +262,14 @@ def "nu-complete kube res" [context: string, offset: int] {
|
||||||
let ctx = $context | argx parse
|
let ctx = $context | argx parse
|
||||||
let kind = $ctx | get _args.1
|
let kind = $ctx | get _args.1
|
||||||
let ns = if ($ctx.namespace? | is-empty) { [] } else { [-n $ctx.namespace] }
|
let ns = if ($ctx.namespace? | is-empty) { [] } else { [-n $ctx.namespace] }
|
||||||
kubectl get $ns $kind | 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] {
|
def "nu-complete kube res via name" [context: string, offset: int] {
|
||||||
let ctx = $context | argx parse
|
let ctx = $context | argx parse
|
||||||
let kind = $env.KUBERNETES_RESOURCE_ABBR | get ($ctx | get _args.0 | str substring (-1..))
|
let kind = $env.KUBERNETES_RESOURCE_ABBR | get ($ctx | get _args.0 | str substring (-1..))
|
||||||
let ns = if ($ctx.namespace? | is-empty) { [] } else { [-n $ctx.namespace] }
|
let ns = if ($ctx.namespace? | is-empty) { [] } else { [-n $ctx.namespace] }
|
||||||
kubectl get $ns $kind | from ssv -a | get NAME
|
kubectl get ...$ns $kind | from ssv -a | get NAME
|
||||||
}
|
}
|
||||||
|
|
||||||
def "nu-complete kube jsonpath" [context: string] {
|
def "nu-complete kube jsonpath" [context: string] {
|
||||||
|
@ -270,13 +289,13 @@ def "nu-complete kube jsonpath" [context: string] {
|
||||||
let row = $path | split row '.'
|
let row = $path | split row '.'
|
||||||
let p = $row | range ..-2 | str join '.'
|
let p = $row | range ..-2 | str join '.'
|
||||||
if ($p | is-empty) {
|
if ($p | is-empty) {
|
||||||
$r = ( kubectl get $ns -o json $kind $res
|
$r = ( kubectl get ...$ns -o json $kind $res
|
||||||
| from json
|
| from json
|
||||||
| columns
|
| columns
|
||||||
| each {|x| $'($p).($x)'}
|
| each {|x| $'($p).($x)'}
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
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 (not ($c | is-empty)) and ($c | describe | str substring 0..5) == 'table' {
|
||||||
|
@ -310,12 +329,12 @@ export def kg [
|
||||||
} else {
|
} else {
|
||||||
[-n $namespace]
|
[-n $namespace]
|
||||||
}
|
}
|
||||||
let r = $r | with-flag
|
if ($r | is-empty) {
|
||||||
let l = $selector | with-flag -l
|
let l = $selector | with-flag -l
|
||||||
if ($jsonpath | is-empty) {
|
if ($jsonpath | is-empty) {
|
||||||
let wide = if $wide {[-o wide]} else {[]}
|
let wide = if $wide {[-o wide]} else {[]}
|
||||||
if ($verbose) {
|
if ($verbose) {
|
||||||
kubectl get -o json $n $k $r $l | from json | get items
|
kubectl get -o json ...$n $k ...$l | from json | get items
|
||||||
| each {|x|
|
| each {|x|
|
||||||
{
|
{
|
||||||
name: $x.metadata.name
|
name: $x.metadata.name
|
||||||
|
@ -329,12 +348,15 @@ export def kg [
|
||||||
}
|
}
|
||||||
| normalize-column-names
|
| normalize-column-names
|
||||||
} else if $watch {
|
} else if $watch {
|
||||||
kubectl get $n $k $r $l $wide --watch
|
kubectl get ...$n $k ...$l ...$wide --watch
|
||||||
} else {
|
} else {
|
||||||
kubectl get $n $k $r $l $wide | from ssv -a | normalize-column-names
|
kubectl get ...$n $k ...$l ...$wide | from ssv -a | normalize-column-names
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
kubectl get $n $k $r $"--output=jsonpath={($jsonpath)}" | from json
|
kubectl get ...$n $k $"--output=jsonpath={($jsonpath)}" | from json
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
kubectl get ...$n $k $r -o json | from json
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,7 +366,7 @@ export def kd [
|
||||||
i: string@"nu-complete kube res"
|
i: string@"nu-complete kube res"
|
||||||
--namespace (-n): string@"nu-complete kube ns"
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
] {
|
] {
|
||||||
kubectl describe ($namespace | with-flag -n) $r $i
|
kubectl describe ...($namespace | with-flag -n) $r $i
|
||||||
}
|
}
|
||||||
|
|
||||||
# kubectl create
|
# kubectl create
|
||||||
|
@ -353,7 +375,7 @@ export def kc [
|
||||||
--namespace (-n): string@"nu-complete kube ns"
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
name:string
|
name:string
|
||||||
] {
|
] {
|
||||||
kubectl create ($namespace | with-flag -n) $r $name
|
kubectl create ...($namespace | with-flag -n) $r $name
|
||||||
}
|
}
|
||||||
|
|
||||||
# kubectl get -o yaml
|
# kubectl get -o yaml
|
||||||
|
@ -362,7 +384,7 @@ export def ky [
|
||||||
i: string@"nu-complete kube res"
|
i: string@"nu-complete kube res"
|
||||||
--namespace (-n): string@"nu-complete kube ns"
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
] {
|
] {
|
||||||
kubectl get ($namespace | with-flag -n) -o yaml $r $i
|
kubectl get ...($namespace | with-flag -n) -o yaml $r $i
|
||||||
}
|
}
|
||||||
|
|
||||||
# kubectl edit
|
# kubectl edit
|
||||||
|
@ -374,7 +396,7 @@ export def ke [
|
||||||
] {
|
] {
|
||||||
let n = $namespace | with-flag -n
|
let n = $namespace | with-flag -n
|
||||||
let r = if ($selector | is-empty) { $r } else {
|
let r = if ($selector | is-empty) { $r } else {
|
||||||
let res = kubectl get $k $n -l $selector | from ssv -a | each {|x| $x.NAME}
|
let res = kubectl get $k ...$n -l $selector | from ssv -a | each {|x| $x.NAME}
|
||||||
if ($res | length) == 1 {
|
if ($res | length) == 1 {
|
||||||
$res.0
|
$res.0
|
||||||
} else if ($res | length) == 0 {
|
} else if ($res | length) == 0 {
|
||||||
|
@ -383,7 +405,7 @@ export def ke [
|
||||||
$res | input list $'select ($k) '
|
$res | input list $'select ($k) '
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
kubectl edit $n $k $r
|
kubectl edit ...$n $k $r
|
||||||
}
|
}
|
||||||
|
|
||||||
# kubectl delete
|
# kubectl delete
|
||||||
|
@ -393,7 +415,7 @@ export def kdel [
|
||||||
--namespace (-n): string@"nu-complete kube ns"
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
--force(-f)
|
--force(-f)
|
||||||
] {
|
] {
|
||||||
kubectl delete ($namespace | with-flag -n) (if $force {[--grace-period=0 --force]} else {[]}) $r $i
|
kubectl delete ...($namespace | with-flag -n) ...(if $force {[--grace-period=0 --force]} else {[]}) $r $i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -406,19 +428,19 @@ export def kgno [] {
|
||||||
def "nu-complete kube deploys and pods" [context: string, offset: int] {
|
def "nu-complete kube deploys and pods" [context: string, offset: int] {
|
||||||
let ctx = $context | argx parse
|
let ctx = $context | argx parse
|
||||||
let ns = $ctx.namespace? | with-flag -n
|
let ns = $ctx.namespace? | with-flag -n
|
||||||
if ($ctx.a? | default false) or ($ctx._pos.pod? | default '' | str ends-with '-') {
|
let all_pods = ($ctx.a? | default false) or ($ctx.all-pods? | default false)
|
||||||
kubectl get $ns pods | from ssv -a | get NAME
|
if $all_pods or ($ctx._pos.pod? | default '' | str ends-with '-') {
|
||||||
|
kubectl get ...$ns pods | from ssv -a | get NAME
|
||||||
} else {
|
} else {
|
||||||
kubectl get $ns deployments | from ssv -a | get NAME | each {|x| $"($x)-"}
|
kubectl get ...$ns deployments | from ssv -a | get NAME | each {|x| $"($x)-"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def "nu-complete kube ctns" [context: string, offset: int] {
|
def "nu-complete kube ctns" [context: string, offset: int] {
|
||||||
let ctx = $context | argx parse
|
let ctx = $context | argx parse
|
||||||
let ns = $ctx.namespace? | with-flag -n
|
let ns = $ctx.namespace? | with-flag -n
|
||||||
let ctn = $ctx.container? | with-flag -c
|
|
||||||
let pod = $ctx | get _args.1
|
let pod = $ctx | get _args.1
|
||||||
kubectl get $ns pod $pod -o jsonpath={.spec.containers[*].name} | split row ' '
|
kubectl get ...$ns pod $pod -o jsonpath={.spec.containers[*].name} | split row ' '
|
||||||
}
|
}
|
||||||
|
|
||||||
# kubectl get pods
|
# kubectl get pods
|
||||||
|
@ -429,7 +451,11 @@ export def kgp [
|
||||||
--selector (-l): string
|
--selector (-l): string
|
||||||
--all (-a)
|
--all (-a)
|
||||||
] {
|
] {
|
||||||
if $all {
|
if not ($r | is-empty) {
|
||||||
|
kubectl get pods ...($namespace | with-flag -n) $r --output=json
|
||||||
|
| from json
|
||||||
|
| {...$in.metadata, ...$in.spec, ...$in.status}
|
||||||
|
} else if $all {
|
||||||
kg pods -a --wide
|
kg pods -a --wide
|
||||||
} else {
|
} else {
|
||||||
kg pods -n $namespace -p $jsonpath -l $selector --wide $r
|
kg pods -n $namespace -p $jsonpath -l $selector --wide $r
|
||||||
|
@ -468,7 +494,7 @@ export def --wrapped ka [
|
||||||
--namespace (-n): string@"nu-complete kube ns"
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
--container(-c): string@"nu-complete kube ctns"
|
--container(-c): string@"nu-complete kube ctns"
|
||||||
--selector(-l): string
|
--selector(-l): string
|
||||||
--all-pods(-a)
|
--all-pods(-a) # for completion
|
||||||
...args
|
...args
|
||||||
] {
|
] {
|
||||||
let n = $namespace | with-flag -n
|
let n = $namespace | with-flag -n
|
||||||
|
@ -505,7 +531,7 @@ export def --wrapped ka [
|
||||||
} else {
|
} else {
|
||||||
[-c $container]
|
[-c $container]
|
||||||
}
|
}
|
||||||
kubectl exec $n -it $pod $c -- (if ($args|is-empty) { 'bash' } else { $args })
|
kubectl exec ...$n -it $pod ...$c -- ...(if ($args|is-empty) {['bash']} else { $args })
|
||||||
}
|
}
|
||||||
|
|
||||||
# kubectl logs
|
# kubectl logs
|
||||||
|
@ -515,7 +541,7 @@ export def kl [
|
||||||
--container(-c): string@"nu-complete kube ctns"
|
--container(-c): string@"nu-complete kube ctns"
|
||||||
--follow(-f)
|
--follow(-f)
|
||||||
--previous(-p)
|
--previous(-p)
|
||||||
--all-pods(-a)
|
--all-pods(-a) # for completion
|
||||||
] {
|
] {
|
||||||
let n = $namespace | with-flag -n
|
let n = $namespace | with-flag -n
|
||||||
let c = $container | with-flag -c
|
let c = $container | with-flag -c
|
||||||
|
@ -526,7 +552,7 @@ export def kl [
|
||||||
} else {
|
} else {
|
||||||
$pod
|
$pod
|
||||||
}
|
}
|
||||||
kubectl logs $n $f $p $trg $c
|
kubectl logs ...$n ...$f ...$p $trg ...$c
|
||||||
}
|
}
|
||||||
|
|
||||||
def "nu-complete port forward type" [] {
|
def "nu-complete port forward type" [] {
|
||||||
|
@ -539,11 +565,11 @@ def "nu-complete kube port" [context: string, offset: int] {
|
||||||
let ns = if ($ctx.namespace? | is-empty) { [] } else { [-n $ctx.namespace] }
|
let ns = if ($ctx.namespace? | is-empty) { [] } else { [-n $ctx.namespace] }
|
||||||
let res = $ctx | get _args.2
|
let res = $ctx | get _args.2
|
||||||
if ($kind | str starts-with 's') {
|
if ($kind | str starts-with 's') {
|
||||||
kubectl get $ns svc $res --output=jsonpath="{.spec.ports}"
|
kubectl get ...$ns svc $res --output=jsonpath="{.spec.ports}"
|
||||||
| from json
|
| from json
|
||||||
| each {|x| {value: $x.port description: $x.name} }
|
| each {|x| {value: $x.port description: $x.name} }
|
||||||
} else {
|
} else {
|
||||||
kubectl get $ns pods $res --output=jsonpath="{.spec.containers[].ports}"
|
kubectl get ...$ns pods $res --output=jsonpath="{.spec.containers[].ports}"
|
||||||
| from json
|
| from json
|
||||||
| each {|x| {value: $x.containerPort description: $x.name?} }
|
| each {|x| {value: $x.containerPort description: $x.name?} }
|
||||||
}
|
}
|
||||||
|
@ -557,9 +583,9 @@ export def kpf [
|
||||||
--local (-l): string
|
--local (-l): string
|
||||||
--namespace (-n): string@"nu-complete kube ns"
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
] {
|
] {
|
||||||
let n = $namespace | with-flag -n
|
let ns = $namespace | with-flag -n
|
||||||
let port = if ($local | is-empty) { $port } else { $"($local):($port)" }
|
let port = if ($local | is-empty) { $port } else { $"($local):($port)" }
|
||||||
kubectl port-forward $n $"($res)/($target)" $port
|
kubectl port-forward ...$ns $"($res)/($target)" $port
|
||||||
}
|
}
|
||||||
|
|
||||||
def "nu-complete kube cp" [cmd: string, offset: int] {
|
def "nu-complete kube cp" [cmd: string, offset: int] {
|
||||||
|
@ -567,10 +593,10 @@ def "nu-complete kube cp" [cmd: string, offset: int] {
|
||||||
let p = $ctx._args | get (($ctx._args | length) - 1)
|
let p = $ctx._args | get (($ctx._args | length) - 1)
|
||||||
let ns = $ctx.namespace? | with-flag -n
|
let ns = $ctx.namespace? | with-flag -n
|
||||||
let c = $ctx.container? | with-flag -c
|
let c = $ctx.container? | with-flag -c
|
||||||
let ctn = kubectl get pod $ns | from ssv -a | each {|x| {description: $x.READY value: $"($x.NAME):" }}
|
let ctn = kubectl get pod ...$ns | from ssv -a | each {|x| {description: $x.READY value: $"($x.NAME):" }}
|
||||||
let n = $p | split row ':'
|
let n = $p | split row ':'
|
||||||
if $"($n | get 0):" in ($ctn | get value) {
|
if $"($n | get 0):" in ($ctn | get value) {
|
||||||
kubectl exec $ns ($n | get 0) $c -- sh -c $"ls -dp ($n | get 1)*"
|
kubectl exec ...$ns ($n | get 0) ...$c -- sh -c $"ls -dp ($n | get 1)*"
|
||||||
| lines
|
| lines
|
||||||
| each {|x| $"($n | get 0):($x)"}
|
| each {|x| $"($n | get 0):($x)"}
|
||||||
} else {
|
} else {
|
||||||
|
@ -587,7 +613,7 @@ export def kcp [
|
||||||
--container (-c): string@"nu-complete kube ctns"
|
--container (-c): string@"nu-complete kube ctns"
|
||||||
--namespace (-n): string@"nu-complete kube ns"
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
] {
|
] {
|
||||||
kubectl cp ($namespace | with-flag -n) $lhs ($container | with-flag -c) $rhs
|
kubectl cp ...($namespace | with-flag -n) $lhs ...($container | with-flag -c) $rhs
|
||||||
}
|
}
|
||||||
|
|
||||||
# kubectl get services
|
# kubectl get services
|
||||||
|
@ -597,7 +623,13 @@ export def kgs [
|
||||||
--jsonpath (-p): string@"nu-complete kube jsonpath"
|
--jsonpath (-p): string@"nu-complete kube jsonpath"
|
||||||
--selector (-l): string
|
--selector (-l): string
|
||||||
] {
|
] {
|
||||||
|
if ($r | is-empty) {
|
||||||
kg services -n $namespace -p $jsonpath -l $selector $r
|
kg services -n $namespace -p $jsonpath -l $selector $r
|
||||||
|
} else {
|
||||||
|
kubectl get svc ...($namespace | with-flag -n) $r --output=json
|
||||||
|
| from json
|
||||||
|
| {...$in.metadata, ...$in.spec, ...$in.status}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# kubectl edit service
|
# kubectl edit service
|
||||||
|
@ -646,8 +678,8 @@ export def ksd [
|
||||||
if ($num | into int) > 9 {
|
if ($num | into int) > 9 {
|
||||||
"too large"
|
"too large"
|
||||||
} else {
|
} else {
|
||||||
let n = $namespace | with-flag -n
|
let ns = $namespace | with-flag -n
|
||||||
kubectl scale $n deployments $d --replicas $num
|
kubectl scale ...$ns deployments $d --replicas $num
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# kubectl scale deployment with reset
|
# kubectl scale deployment with reset
|
||||||
|
@ -661,9 +693,9 @@ export def ksdr [
|
||||||
} else if $num <= 0 {
|
} else if $num <= 0 {
|
||||||
"too small"
|
"too small"
|
||||||
} else {
|
} else {
|
||||||
let n = $namespace | with-flag -n
|
let ns = $namespace | with-flag -n
|
||||||
kubectl scale $n deployments $d --replicas 0
|
kubectl scale ...$ns deployments $d --replicas 0
|
||||||
kubectl scale $n deployments $d --replicas $num
|
kubectl scale ...$ns deployments $d --replicas $num
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -678,9 +710,9 @@ export def krhd [
|
||||||
--revision (-v): int
|
--revision (-v): int
|
||||||
dpl: string@"nu-complete kube res via name"
|
dpl: string@"nu-complete kube res via name"
|
||||||
] {
|
] {
|
||||||
let n = $namespace | with-flag -n
|
let ns = $namespace | with-flag -n
|
||||||
let v = if ($revision|is-empty) { [] } else { [ $"--revision=($revision)" ] }
|
let v = if ($revision|is-empty) { [] } else { [ $"--revision=($revision)" ] }
|
||||||
kubectl $n rollout history $"deployment/($dpl)" $v
|
kubectl ...$ns rollout history $"deployment/($dpl)" ...$v
|
||||||
}
|
}
|
||||||
|
|
||||||
# kubectl rollout undo
|
# kubectl rollout undo
|
||||||
|
@ -689,9 +721,9 @@ export def krud [
|
||||||
--revision (-v): int
|
--revision (-v): int
|
||||||
dpl: string@"nu-complete kube res via name"
|
dpl: string@"nu-complete kube res via name"
|
||||||
] {
|
] {
|
||||||
let n = $namespace | with-flag -n
|
let ns = $namespace | with-flag -n
|
||||||
let v = if ($revision|is-empty) { [] } else { [ $"--to-revision=($revision)" ] }
|
let v = if ($revision|is-empty) { [] } else { [ $"--to-revision=($revision)" ] }
|
||||||
kubectl $n rollout undo $"deployment/($dpl)" $v
|
kubectl ...$ns rollout undo $"deployment/($dpl)" ...$v
|
||||||
}
|
}
|
||||||
export alias ksss = kubectl scale statefulset
|
export alias ksss = kubectl scale statefulset
|
||||||
export alias krsss = kubectl rollout status statefulset
|
export alias krsss = kubectl rollout status statefulset
|
||||||
|
@ -712,8 +744,8 @@ export def ktp [
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let n = $namespace | with-flag -n
|
let ns = $namespace | with-flag -n
|
||||||
kubectl top pod $n | from ssv -a | rename name cpu mem
|
kubectl top pod ...$ns | from ssv -a | rename name cpu mem
|
||||||
| each {|x|
|
| each {|x|
|
||||||
{
|
{
|
||||||
name: $x.name
|
name: $x.name
|
||||||
|
@ -931,7 +963,7 @@ export def kgh [
|
||||||
] {
|
] {
|
||||||
if ($name | is-empty) {
|
if ($name | is-empty) {
|
||||||
let ns = if $all { [--all] } else { $namespace | with-flag -n }
|
let ns = if $all { [--all] } else { $namespace | with-flag -n }
|
||||||
helm list $ns --output json
|
helm list ...$ns --output json
|
||||||
| from json
|
| from json
|
||||||
| update updated {|x|
|
| update updated {|x|
|
||||||
$x.updated
|
$x.updated
|
||||||
|
@ -940,11 +972,11 @@ export def kgh [
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if $manifest {
|
if $manifest {
|
||||||
helm get manifest $name ($namespace | with-flag -n)
|
helm get manifest $name ...($namespace | with-flag -n)
|
||||||
} else if $values {
|
} else if $values {
|
||||||
helm get values $name ($namespace | with-flag -n)
|
helm get values $name ...($namespace | with-flag -n)
|
||||||
} else {
|
} else {
|
||||||
helm get notes $name ($namespace | with-flag -n)
|
helm get notes $name ...($namespace | with-flag -n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -976,14 +1008,15 @@ export def kah [
|
||||||
valuefile: path
|
valuefile: path
|
||||||
--values (-v): any
|
--values (-v): any
|
||||||
--namespace (-n): string@"nu-complete kube ns"
|
--namespace (-n): string@"nu-complete kube ns"
|
||||||
|
--ignore-image (-i) # for kdh
|
||||||
] {
|
] {
|
||||||
let update = $name in (
|
let update = $name in (
|
||||||
helm list ($namespace | with-flag -n) --output json
|
helm list ...($namespace | with-flag -n) --output json
|
||||||
| from json | get name
|
| from json | get name
|
||||||
)
|
)
|
||||||
let act = if $update { [upgrade] } else { [install] }
|
let act = if $update { [upgrade] } else { [install] }
|
||||||
let values = if ($values | is-empty) { [] } else { [--set-json (record-to-set-json $values)] }
|
let values = if ($values | is-empty) { [] } else { [--set-json (record-to-set-json $values)] }
|
||||||
helm $act $name $chart -f $valuefile $values ($namespace | with-flag -n)
|
helm ...$act $name $chart -f $valuefile ...$values ...($namespace | with-flag -n)
|
||||||
}
|
}
|
||||||
|
|
||||||
# helm diff
|
# helm diff
|
||||||
|
@ -997,10 +1030,10 @@ export def kdh [
|
||||||
--has-plugin (-h)
|
--has-plugin (-h)
|
||||||
] {
|
] {
|
||||||
if $has_plugin {
|
if $has_plugin {
|
||||||
helm diff $name $chart -f $valuefile ($namespace | with-flag -n)
|
helm diff $name $chart -f $valuefile ...($namespace | with-flag -n)
|
||||||
} else {
|
} else {
|
||||||
let update = $name in (
|
let update = $name in (
|
||||||
helm list ($namespace | with-flag -n) --output json
|
helm list ...($namespace | with-flag -n) --output json
|
||||||
| from json | get name
|
| from json | get name
|
||||||
)
|
)
|
||||||
if not $update {
|
if not $update {
|
||||||
|
@ -1010,7 +1043,7 @@ export def kdh [
|
||||||
|
|
||||||
let values = if ($values | is-empty) { [] } else { [--set-json (record-to-set-json $values)] }
|
let values = if ($values | is-empty) { [] } else { [--set-json (record-to-set-json $values)] }
|
||||||
let target = $'/tmp/($chart | path basename).($name).out.yaml'
|
let target = $'/tmp/($chart | path basename).($name).out.yaml'
|
||||||
helm template --debug $name $chart -f $valuefile $values ($namespace | with-flag -n) | save -f $target
|
helm template --debug $name $chart -f $valuefile ...$values ...($namespace | with-flag -n) | save -f $target
|
||||||
if $ignore_image {
|
if $ignore_image {
|
||||||
do -i { yq -i ea 'del(.spec.template.spec.containers.[].image)' $target }
|
do -i { yq -i ea 'del(.spec.template.spec.containers.[].image)' $target }
|
||||||
}
|
}
|
||||||
|
@ -1037,7 +1070,7 @@ export def kh [
|
||||||
let values = if ($values | is-empty) { [] } else { [--set-json (record-to-set-json $values)] }
|
let values = if ($values | is-empty) { [] } else { [--set-json (record-to-set-json $values)] }
|
||||||
let target = $valuefile | split row '.' | range ..-2 | append [out yaml] | str join '.'
|
let target = $valuefile | split row '.' | range ..-2 | append [out yaml] | str join '.'
|
||||||
if (not ($target | path exists)) and (([yes no] | input list $'create ($target)?') in [no]) { return }
|
if (not ($target | path exists)) and (([yes no] | input list $'create ($target)?') in [no]) { return }
|
||||||
helm template --debug $app $chart -f $valuefile $values ($namespace | with-flag -n)
|
helm template --debug $app $chart -f $valuefile ...$values ...($namespace | with-flag -n)
|
||||||
| save -f $target
|
| save -f $target
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue