# Interactive completion setup. # Carapace is wrapped so empty results fall back to Nushell path completion. # Helpers expected by some Carapace env-aware completions. def --env get-env [name: string] { $env | get -o $name } def --env set-env [name: string, value: any] { load-env { $name: $value } } def --env unset-env [name: string] { hide-env $name } let carapace_completer = {|spans: list| load-env { CARAPACE_SHELL_BUILTINS: (help commands | where category != "" | get name | each { split row " " | first } | uniq | str join "\n") CARAPACE_SHELL_FUNCTIONS: (help commands | where category == "" | get name | each { split row " " | first } | uniq | str join "\n") } let expanded_alias = (scope aliases | where name == $spans.0 | get -o 0.expansion) let spans = if $expanded_alias != null { $spans | skip 1 | prepend ($expanded_alias | split row " " | take 1) } else { $spans } let result = (do --ignore-errors { ^carapace $spans.0 nushell ...$spans | from json }) if ($result | is-empty) { let current = ($spans | last | default "") if ($current | str starts-with "-") { [] } else { null } } else { $result } } let external = ($env.config.completions.external? | default {}) $env.config.completions.external = ($external | merge { enable: true completer: $carapace_completer })