move cache into $nu.data-dir/cache

This commit is contained in:
nash 2024-06-26 09:26:07 +08:00
parent 4db7930605
commit 4608fc3bf0
6 changed files with 8 additions and 8 deletions

View File

@ -79,7 +79,7 @@ export def 'cwd history delete' [cwd] {
export-env {
$env.cwd_history_full = false
$env.cwd_history_file = $'($env.HOME)/.cache/nu_cwd_history.sqlite'
$env.cwd_history_file = ([$nu.data-dir 'cache'] | path join 'nu_cwd_history.sqlite')
if not ($env.cwd_history_file | path exists) {
empty-sqlite | save -f $env.cwd_history_file

View File

@ -1,5 +1,5 @@
export-env {
for c in [nerdctl podman docker] {
for c in [podman nerdctl docker] {
if (which $c | is-not-empty) {
$env.docker-cli = $c
break

View File

@ -3,7 +3,7 @@ use utils.nu *
export def "nu-complete kube ctx" [] {
let k = (kube-config)
let cache = $'($env.HOME)/.cache/nu-complete/k8s/($k.path | path basename).json'
let cache = ([$nu.data-dir 'cache' 'k8s'] | path join $'($k.path | path basename).json')
let data = ensure-cache-by-lines $cache $k.path { ||
let clusters = $k.data | get clusters | select name cluster.server
let data = $k.data
@ -38,7 +38,7 @@ export def "nu-complete kube ns" [] {
export def "nu-complete kube kind" [] {
let ctx = (kube-config)
let cache = $'($env.HOME)/.cache/nu-complete/k8s-api-resources/($ctx.data.current-context).json'
let cache = ([$nu.data-dir 'cache' 'k8s-api-resources'] | path join $'($ctx.data.current-context).json')
ensure-cache-by-lines $cache $ctx.path {||
kubectl api-resources | from ssv -a
| each {|x| {value: $x.NAME description: $x.SHORTNAMES} }

View File

@ -266,7 +266,7 @@ export def --wrapped ka [
let n = $namespace | with-flag -n
let pod = if ($selector | is-empty) {
if ($pod | str ends-with '-') {
$"deployment/($pod | str substring ..<-1)"
$"deployment/($pod | str trim --char '-' --right)"
} else {
$pod
}

View File

@ -14,10 +14,10 @@ def "kube ctx" [] {
mut cache = ''
mut file = ''
if ($env.KUBECONFIG? | is-empty) {
$cache = $'($env.HOME)/.cache/nu-power/kube.json'
$cache = ([$nu.data-dir 'cache' 'power'] | path join 'kube.json')
$file = $"($env.HOME)/.kube/config"
} else {
$cache = $"($env.HOME)/.cache/nu-power/kube-($env.KUBECONFIG | str replace -a '/' ':').json"
$cache = ([$nu.data-dir 'cache' 'power'] | path join $"kube-($env.KUBECONFIG | str replace -a '/' ':').json")
$file = $env.KUBECONFIG
}
if not ($file | path exists) { return null }

View File

@ -57,7 +57,7 @@ def fmt-group [p] {
}
def "ssh-hosts" [] {
let cache = $'($env.HOME)/.cache/nu-complete/ssh.json'
let cache = ([$nu.data-dir 'cache'] | path join 'ssh.json')
ensure-cache $cache [~/.ssh/config ~/.ssh/config*/* ] { ||
let data = (ssh-list | each {|x|
let uri = $"($x.User)@($x.HostName):($x.Port)"