chore: cleanup

This commit is contained in:
johannes committed 2026-07-30 00:08:37 +02:00
1 parent 2a0f4f6851
commit d3460b52ea
42 files changed
+14 -2560

No files matched your search

+8 -68
View File
@@ -26,76 +26,16 @@ if not ($nu.cache-dir | path exists) {
mkdir $"($nu.cache-dir)"
}
def create_cache [name: string, generator: closure] {
let file = $"($nu.cache-dir)/($name).nu"
if not ($file | path exists) {
do $generator | save -f $file
}
}
if (which starship | is-not-empty) { starship init nu | save -f $"($nu.cache-dir)/starship.nu" } else { "" | save -f $"($nu.cache-dir)/starship.nu" }
if (which zoxide | is-not-empty) { zoxide init nushell | save -f $"($nu.cache-dir)/zoxide.nu" } else { "" | save -f $"($nu.cache-dir)/zoxide.nu" }
if (which atuin | is-not-empty) { atuin init nu | save -f $"($nu.cache-dir)/atuin.nu" } else { "" | save -f $"($nu.cache-dir)/atuin.nu" }
$env.CARAPACE_BRIDGES = 'zsh,fish,bash,inshellisense'
if (which carapace | is-not-empty) { ^carapace _carapace nushell | str replace '$env.config = $current' '$env.config = ($env.config? | default {} | merge $current)' | save -f $"($nu.cache-dir)/carapace.nu" } else { "" | save -f $"($nu.cache-dir)/carapace.nu" }
create_cache starship { starship init nu }
create_cache zoxide { zoxide init nushell }
create_cache atuin { atuin init nu }
create_cache carapace {
$env.CARAPACE_BRIDGES = 'zsh,fish,bash,inshellisense';
^carapace _carapace nushell | str replace '$env.config = $current' '$env.config = ($env.config? | default {} | merge $current)'
}
def --env apply_mise_env [mise_bin: string] {
let vars = (
^$mise_bin hook-env -s nu
| from csv --noheaders --no-infer
| rename 'op' 'name' 'value'
)
for var in $vars {
if $var.op == "set" {
if ($var.name | str uppercase) == "PATH" {
$env.PATH = ($var.value | split row (char esep))
} else {
load-env {($var.name): $var.value}
}
} else if $var.op == "hide" and $var.name in $env {
hide-env -i $var.name
}
}
}
def --env add-hook [field: cell-path new_hook: any] {
let field = $field | split cell-path | update optional true | into cell-path
let old_config = $env.config? | default {}
let old_hooks = $old_config | get $field | default []
$env.config = ($old_config | upsert $field ($old_hooks ++ [$new_hook]))
}
let mise_candidates = if ($nu.os-info.name == "macos") {
["/opt/homebrew/bin/mise" "~/.local/bin/mise" "mise"]
if (which mise | is-not-empty) {
mise activate nu | save -f $"($nu.cache-dir)/mise.nu"
} else {
["~/.local/bin/mise" "/home/linuxbrew/.linuxbrew/bin/mise" "mise"]
}
let mise_bin = (
$mise_candidates
| each {|candidate|
if $candidate == "mise" {
if (which mise | is-empty) { null } else { "mise" }
} else {
let expanded = ($candidate | path expand)
if ($expanded | path exists) { $expanded } else { null }
}
}
| compact
| get 0?
)
if $mise_bin != null {
$env.MISE_SHELL = "nu"
apply_mise_env $mise_bin
let mise_hook = {
condition: { "MISE_SHELL" in $env }
code: { apply_mise_env $mise_bin }
}
add-hook hooks.pre_prompt $mise_hook
add-hook hooks.env_change.PWD $mise_hook
"" | save -f $"($nu.cache-dir)/mise.nu"
}
# Deduplicate PATH at the end