1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 22:57:46 +00:00

improve kconf import (#481)

* improve kconf import

The order of fields loaded via `from yaml` is unstable, so use yq to
read it as json, and then load it by `from json`.

Aims to be `diff` friendly.

Remove the square brackets from the week field and use color to
distinguish it, taking up less space.

* kube_stat shows $ctx.NAME instead of complex combination of $ctx.AUTHINFO and $ctx.CLUSTER

- Improve the default theme of kube_stat.
- Clean up duplicate comments in `kubernetes.nu`.

* when power's DECORATOR mode is `power`, allows to dynamically change the background color

- components now needs to return two values in an array, the first value is the background color, and the second value is the original value.
- as an example, `atuin_stat` reveal its status with two different colors instead of showing or hiding

* allowing pass `config` when register or inject a component

The main difference between `config` and `theme` is: theme assumes you pass a color and will apply with `ansi -e {fg : $arg}`

And in most cases, you don't need to pass `config`

* added new function `power set`

time_segment allows format control via option `short`

* rename `nu-complete kube def` to `nu-complete kube kind`

- get all resources via `kubectl api-resources`
- enable cache

* use `from yaml` instead of `yq -o=json | from json` (for next version)

* nu-complete kube kind: add SHORTNAMES as description

* Fix the caching mechanism of `kube ctx` and `kube kind`

based on the number of file lines instead of modification time.

Because switching the context will change the content of the file, the time will be updated every time

* Added new command `kcache flush` to rebuild the cache.

Sometimes, such as manually editing the cluster address in the
configuration file, the number of lines has not changed, and the cache
does need to be refreshed

* use `path dirname` instead of `dirname`

* applying `ensure-cache-by-lines` in `kube_stat`

---------

Co-authored-by: agent <agent@nuc>
This commit is contained in:
fj0r 2023-05-11 19:37:39 +08:00 committed by GitHub
parent ee996ec169
commit 2d6f32657a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 164 additions and 93 deletions

View file

@ -3,7 +3,7 @@ export def ensure-cache [cache path action] {
if ($ts | is-empty) { return false }
let tc = (do -i { ls $cache | get 0.modified })
if not (($cache | path exists) and ($ts < $tc)) {
mkdir (dirname $cache)
mkdir ($cache | path dirname)
do $action | save -f $cache
}
open $cache