Enables tab autocomplete for the dotnet CLI. Also use when the user mentions "dotnet autocomplete," "dotnet tab completion," "CLI completion," "shell completion for dotnet," or "dotnet intellisense in terminal."
Enable tab autocomplete for the dotnet CLI in your preferred shell.
Determine .NET version (CRITICAL - commands differ by version)
dotnet sdk check
dotnet completions script <shell> (native completions)dotnet complete --position (dynamic completions)Ask user which shells they use, allowing multi-select:
For each user shell:
Detect profile file location based on shell:
| Shell | Profile Path |
|---|---|
| PowerShell | $PROFILE |
| bash | ~/.bashrc |
| zsh | ~/.zshrc |
| fish | ~/.config/fish/config.fish |
| nushell | ~/.config/nushell/config.nu |
Check if completion already configured
Append completion script to profile based on .NET version and shell
Inform user to restart their shell or source the profile
PowerShell:
dotnet completions script pwsh | Out-String | Invoke-Expression
bash:
eval "$(dotnet completions script bash)"
zsh:
eval "$(dotnet completions script zsh)"
fish:
dotnet completions script fish | source
nushell: See .NET CLI docs for config.nu setup.
PowerShell:
# dotnet CLI tab completion
Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
dotnet complete --position $cursorPosition "$commandAst" | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
bash:
# dotnet CLI tab completion
_dotnet_bash_complete() {
local cur="${COMP_WORDS[COMP_CWORD]}"
local IFS=$'\n'
local candidates
read -d '' -ra candidates < <(dotnet complete --position "${COMP_POINT}" "${COMP_LINE}" 2>/dev/null)
read -d '' -ra COMPREPLY < <(compgen -W "${candidates[*]}" -- "$cur")
}
complete -f -F _dotnet_bash_complete dotnet
zsh:
# dotnet CLI tab completion
_dotnet_zsh_complete() {
local completions=("$(dotnet complete --position ${CURSOR} "${BUFFER}" 2>/dev/null)")
reply=("${(ps:\n:)completions}")
}
compctl -K _dotnet_zsh_complete dotnet
fish:
# dotnet CLI tab completion
complete -f -c dotnet -a "(dotnet complete --position (commandline -cp) (commandline -op))"
nushell:
# Add to external_completer in config.nu
let external_completer = {|spans|
match $spans.0 {
dotnet => (
dotnet complete (
$spans | skip 1 | str join " "
) | lines
)
}
}
dotnet sdk check fails: Ensure .NET SDK is installeddotnet completions commanddotnet complete with dynamic scripts