Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

nushell/modules/mise-completion-handler.nu

Raw
use mise-completions.nu

export-env {
    let carapace = $env.config.completions.external.completer

    $env.config.completions.external.completer = {|place|
        let command = (scope aliases | where name == $place.command.0 | get -o 0.expansion | default $place.command.0)
        if ($command | path basename | str replace --regex '(?i)\.exe$' '') == 'mise' {
            mise-completions ($place | upsert command ($place.command | skip 1 | prepend $command))
        } else {
            let completions = (do $carapace $place)
            # Empty positional result -> null -> Nushell falls back to path completion.
            if ($completions | is-empty) and not ($place.command | last | str starts-with '-') {
                null
            } else {
                $completions
            }
        }
    }
}