nichts/parts/pkgs/extraPackages/nushell/config.nu

106 lines
2.9 KiB
Text
Raw Normal View History

let starship_installed = not (which starship | is-empty)
2024-09-20 15:45:44 +02:00
let direnv_installed = not (which direnv | is-empty)
let carapace_installed = not (which carapace | is-empty)
2024-09-20 15:45:44 +02:00
2024-09-22 00:20:12 +02:00
alias c = clear
alias cc = cd; clear
alias h = hx
alias e = emacsclient
alias g = git
alias lg = lazygit
# alias cd = z
# alias ci = zi
let zoxide_completer = {|spans|
$spans | skip 1 | zoxide query -l ...$in | lines | where {|x| $x != $env.PWD}
}
# =============================================================================
let carapace_completer = {|spans: list<string>|
carapace $spans.0 nushell ...$spans
| from json
| if ($in | default [] | where value =~ '^-.*ERR$' | is-empty) { $in } else { null }
}
# =============================================================================
let fish_completer = {|spans|
fish --command $'complete "--do-complete=($spans | str join " ")"'
| $"value(char tab)description(char newline)" + $in
| from tsv --flexible --no-infer
}
# =============================================================================
# This completer will use carapace by default
let external_completer = {|spans|
let expanded_alias = scope aliases
| where name == $spans.0
| get -i 0.expansion
let spans = if $expanded_alias != null {
$spans
| skip 1
| prepend ($expanded_alias | split row ' ' | take 1)
} else {
$spans
}
match $spans.0 {
# carapace completions are incorrect for nu
nu => $fish_completer
# fish completes commits and branch names in a nicer way
git => $fish_completer
# carapace doesn't have completions for asdf
# asdf => $fish_completer
# use zoxide completions for zoxide commands
__zoxide_z | __zoxide_zi => $zoxide_completer
_ => $carapace_completer
} | do $in $spans
}
# =============================================================================
if $starship_installed {
$env.STARSHIP_SHELL = "nu"
$env.STARSHIP_SESSION_KEY = (random chars -l 16)
$env.STARSHIP_SESSION_KEY = (random chars -l 16)
$env.PROMPT_MULTILINE_INDICATOR = (starship prompt --continuation)
$env.PROMPT_INDICATOR = ""
$env.PROMPT_COMMAND = {|| starship prompt $"--cmd-duration=($env.CMD_DURATION_MS)" $"--status=($env.LAST_EXIT_CODE)" }
$env.PROMPT_COMMAND_RIGHT = ''
} else {}
# =============================================================================
$env.config = {
show_banner: false
2024-09-20 15:45:44 +02:00
hooks: {
pre_prompt: [{ ||
if $direnv_installed {
direnv export json | from json | default {} | load-env
} else { return }
}]
}
2024-09-20 23:42:10 +02:00
rm: {
always_trash: true
}
table: {
mode: compact
index_mode: auto
}
2024-09-22 00:20:12 +02:00
2024-09-20 23:42:10 +02:00
completions: {
quick: true
partial: true
case_sensitive: false
algorithm: "fuzzy"
2024-09-22 00:20:12 +02:00
external: {
2024-09-20 23:42:10 +02:00
enable: true
2024-09-22 00:20:12 +02:00
completer: $external_completer
2024-09-20 23:42:10 +02:00
max_results: 100
2024-09-22 00:20:12 +02:00
}
}
}